0
{
  "customer": {
    "ssoId":"B56789",
    "brand":"123-reg",
    "forename":"John",
    "surname":"Doe",
    "title":"Mr",
    "companyName":"Unilever",
    "primaryEmail":"john.doe@unilever.com",
    "currency":"$",
    "language":"English",
    "vatNumber":"D4531234",
    "vatCode":"12B6",
    "ipAddress":"127.0.0.1"
  }
}

That's my JSON file I'm trying to unmarshal using Apache camel to a POJO but it keeps throwing that error! When I add the @JsonIngoreProperties, it returns a null object without populating the POJO.

@Data
@JsonInclude(NON_EMPTY)
public final class Customer{
    @JsonProperty(value = "ssoId", required = true)
    private String ssoId;

    @JsonProperty(value = "brand", required = true)
    private String brand;

    @JsonProperty(value = "forename", required = true)
    private String forename;
    //......
}
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "customer" (class com.heg.esb.model.Customer), not
marked as ignorable (17 known properties: "addresses", "phones",
"brand", "companyName", "ssoId", "ipAddress", "currency", "vatNumber",
"vatCode", "title", "primaryEmail", "surname", "lastVerificationDate",
"forename", "lastModifiedDate", "createdDate", "language"])
 at [Source: java.io.ByteArrayInputStream@3844c08b; line: 2, column: 16] (through reference chain: com.heg.esb.model.Customer["customer"])
 at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51)
 at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:839)
 at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1045)
 at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1352)
 at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1330)
 at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:264)
 at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
 at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3736)
 at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2796)
 at org.apache.camel.component.jackson.JacksonDataFormat.unmarshal(JacksonDataFormat.java:173)
 at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69)
 at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
 at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
 at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
 at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
 at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
 at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
 at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
 at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
 at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
 at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
 at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)
 at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)
 at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:112)
Kenster
  • 23,465
  • 21
  • 80
  • 106
Sammy65
  • 627
  • 2
  • 12
  • 28
  • It looks like that there is `customer` field in `Customer` class without annotated with either @JsonProperty or @JsonIgnore? – Wilson Jun 27 '16 at 14:53
  • That's not meant to be a property but what I need to use in my Jsonpath within camel blueprint to identify with POJO it should marshall it to. – Sammy65 Jun 27 '16 at 15:02
  • Oh! I just noticed it was marked duplicate. Well, it wasn't as I had looked at the link added before posting it. I was asking how to transform the JSON file above to POJO as JSON was complaining about the outer "customer" before the curly brackets because it needed a wrapper class to understand what to do with the file. I used this website to solve my challenge "http://www.jsonschema2pojo.org/" – Sammy65 Nov 17 '16 at 16:00

1 Answers1

0

You need to have public setters in the POJO for each private field you're trying to have Jackson populate.

Also, you do not need to specify "value" in the @JsonProperty annotation if it's the same as the field name.

java-addict301
  • 3,220
  • 2
  • 25
  • 37
  • The @Data from lombok provides the getters and setters automatically. I couldn't include the "required" parameter without that. – Sammy65 Jun 27 '16 at 15:00