java.util.ArrayList[4]->com.somepackage.transport.Foo["assets"]->com.somepackage.transport.Blah["htmls"])Below is an idea of how my code is organized:public class Whatever {/*** Response data of pagination*/@JsonProperty("data")private List data;/*** Data Structure which provide the pagination structures for collection*/private Pagination pagination;}@JsonInclude(JsonInclude.Include.NON_EMPTY)@JsonIgnoreProperties(ignoreUnknown = true)public class Foo {...@JsonProperty("assets")public Blah getAssets() {return adaptee != null ? new Blah(adaptee.getAssets()) : null;}...}@JsonInclude(JsonInclude.Include.NON_EMPTY)@JsonIgnoreProperties(ignoreUnknown = true)public class Blah {...@JsonProperty("htmls")public Set getHtmls() {Set ihtmls = assetEntity.getHtmls();if (ihtmls == null) {return new HashSet();}Set htmls = null;if (!ihtmls.isEmpty()) {htmls =..." />

Getting com.fasterxml.jackson.databind.JsonMappingException for null properties

I am getting a com.fasterxml.jackson.databind.JsonMappingException even annotating classes with @JsonInclude(JsonInclude.Include.NON_EMPTY) and @JsonIgnoreProperties(ignoreUnknown = true).

The message is as follows:

java.lang.NullPointerException) (through reference chain: com.somepackage.Whatever["data"]->java.util.ArrayList[4]->com.somepackage.transport.Foo["assets"]->com.somepackage.transport.Blah["htmls"])

Below is an idea of how my code is organized:

public class Whatever {

/**

* Response data of pagination

*/

@JsonProperty("data")

private List data;

/**

* Data Structure which provide the pagination structures for collection

*/

private Pagination pagination;

}

@JsonInclude(JsonInclude.Include.NON_EMPTY)

@JsonIgnoreProperties(ignoreUnknown = true)

public class Foo {

...

@JsonProperty("assets")

public Blah getAssets() {

return adaptee != null ? new Blah(adaptee.getAssets()) : null;

}

...

}

@JsonInclude(JsonInclude.Include.NON_EMPTY)

@JsonIgnoreProperties(ignoreUnknown = true)

public class Blah {

...

@JsonProperty("htmls")

public Set getHtmls() {

Set ihtmls = assetEntity.getHtmls();

if (ihtmls == null) {

return new HashSet<>();

}

Set htmls = null;

if (!ihtmls.isEmpty()) {

htmls =...

Read More »

By: StackOverFlow - 5 days ago

Related Posts