Home » Java » java – Jackson configuration with spring hateoas-Exceptionshub

java – Jackson configuration with spring hateoas-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a problem with null fields in spring hateoas.

    {
      "rel": "...",
      "href": "http://...",
      "hreflang": null,
      "media": null,
      "title": null,
      "type": null,
      "deprecation": null
    }

I solved this problem using mixIn.

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties({"template", "templated"})
public abstract class LinkMixIn {
}

@Configuration
public class JacksonConfiguration {

@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.addMixIn(Link.class, LinkMixIn.class);

    return mapper;
}
}

But after that i have a problem with adapters (they didn’t work).

@XmlJavaTypeAdapter(SimpleDateAdapter.class)
private Date createdAt;

How i can solve problem with null fields in spring hateoas and not break the adapters?

How to&Answers: