Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Null value ignored for unwrapped objects #125

Description

@mafor

Hi. I have faced a minor issue when using JsonUnwrapped annotation together with a custom null value: null value is ignored when serializing nested objects. Here comes an example:

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;

class Inner {
    public String f1;
    public String f2;
    public String f3;
}

class Outer {
    public String f1;
    @JsonUnwrapped
    public Inner f2;
}

public class Test {

    public static void main(String args[]) throws JsonProcessingException {

        final CsvMapper mapper = new CsvMapper();

        // Set null value to 'null'
        final CsvSchema schema = mapper.schemaFor(Outer.class).withNullValue("null");

        // Create an object. All the fields are NULLs
        final Outer outer = new Outer();

        // Serialize the object.
        // I would expect: null,null,null,null
        // I get: null,,,
        System.out.println(mapper.writer(schema).writeValueAsString(outer));
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions