Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8887611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:51:07+00:00 2026-06-14T21:51:07+00:00

When sending out a JSON to be deserialized by Jackson it seems that if

  • 0

When sending out a JSON to be deserialized by Jackson it seems that if the last value of a subelement is null, Jackson will abort the deserialization.


Bad:

If I send this JSON to my receiver (below), the mapped Content object will be null, because the deserialization stops at image:

{"user":{"id":"1", "token":"ABC", "image":null},"content":{"id":"2"}}

Good:

If I send it like this, image will still have the null value as desired but the Content object will be created with its id:

{"user":{"id":"1", "image":null, "token":"ABC"},"content":{"id":"2"}}

This looks like a bug to me..?!


simple Receiver:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response create(UserContent source) {
        UserContent dbResult = manager.create(source);
        return Response.status(200)
                .entity(dbResult.getId().toString()).build();
}

Serializer

 public static String objectToString(Object object) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));

        Writer strWriter = new StringWriter();
        try {
            mapper.writeValue(strWriter, object);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        String userDataJSON = strWriter.toString();

        return userDataJSON;
    }

Can I set up my ObjectMapper to serialize all null as "" or empty Object on my sending side?

If I pass a UserContent object with a null property to the above method, the resulting JSON will have null values like the example above and should the last item of a list have the value null, deserialization will abort causing NullPointerExceptions in my backend.


edit – the UserContent class:

@Entity
@Table(name = "user_content")
@XmlRootElement
public class UserContent extends org.springframework.data.jpa.domain.AbstractPersistable<Long> {
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @Fetch(FetchMode.JOIN)
    private User user;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "content_post_id", nullable = false)
    @Fetch(FetchMode.JOIN)
    private Contentcontent;

    // more properties...
}

our dependencies:

<properties>
    <jersey-version>1.14</jersey-version>
</properties>
            <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.5</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${jersey-version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey-version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>${jersey-version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>${jersey-version}</version>
    </dependency>


    <dependency>
        <groupId>com.sun.jersey.jersey-test-framework</groupId>
        <artifactId>jersey-test-framework-grizzly2</artifactId>
        <version>${jersey-version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>${jersey-version}</version>
        <scope>test</scope>
    </dependency>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:51:08+00:00Added an answer on June 14, 2026 at 9:51 pm

    Our solution right now for this strange beahavior is to ignore all null values on Serialization by configuring the ObjectMapper:

    mapper.setSerializationInclusion(Inclusion.NON_NULL);
    

    Which we can do as we controle both sides. I’m still curious about how to actually handle an incoming null value constelation as described above in case we make the REST service publicly available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Will be sending out e-mails from an application on a scheduled basis. I have
I am using a script that is sending out emails and I am receiving
I am facing problems in sending json response to php that I get from
i am sending out email to a list of people. I have the list
I have seen a bunch of examples for sending emails out when a repo
So, after spending the last week carefully designing and planning out my app, a
Sending the same pointer into two different shared_ptr 's is bad, it causes double
I'm getting a strange error, and I cannot figure out the problem. I'm sending
I am sending a string down from a websockets server to my client that
Sending objects to ASP.NET from JSON works fine if you have a class built

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.