java - Getting unrecognized property exception though the property has been mentioned -


i getting below exception when try read string message coming in.

com.fasterxml.jackson.databind.exc.unrecognizedpropertyexception: unrecognized field "eventid" (class org.json.jsonobject), not marked ignorable (0 known properties: ])  @ [source: {"messagetype": "eventsubscription","messagedata": {"eventid": ["proximitysensorinrange", "proximitysensoroutofrange", "barcodebarcodescanned", "rfidrfidscanned", "externalrfidexternalrfidscanned", "buttonsbuttonpressed", "testclientevent", "applicationinteractiondetected", "productadditionmethodbarcode", "productadditionmethodrfid", "productadditionmethodsearchandadd", "kohlsofferkohlscashused", "kohlsoffergiftcardused", "kohlsofferpromocodesused", "searchinputkeyedin", "searchinputvoice", "kubeusagetime", "productadditionmethodrecommendation", "productadditionmethodupcsearch"]}}; line: 1, column: 65] (through reference chain: com.kube.dataobjects.hosteventobject["messagedata"]->org.json.jsonobject["eventid"]) @ com.fasterxml.jackson.databind.exc.unrecognizedpropertyexception.from(unrecognizedpropertyexception.java:51) @ com.fasterxml.jackson.databind.deserializationcontext.reportunknownproperty(deserializationcontext.java:731) @ com.fasterxml.jackson.databind.deser.std.stddeserializer.handleunknownproperty(stddeserializer.java:915) @ com.fasterxml.jackson.databind.deser.beandeserializerbase.handleunknownproperty(beandeserializerbase.java:1292) @ com.fasterxml.jackson.databind.deser.beandeserializerbase.handleunknownvanilla(beandeserializerbase.java:1270) @ com.fasterxml.jackson.databind.deser.beandeserializer.vanilladeserialize(beandeserializer.java:247) @ com.fasterxml.jackson.databind.deser.beandeserializer.deserialize(beandeserializer.java:118) @ com.fasterxml.jackson.databind.deser.settablebeanproperty.deserialize(settablebeanproperty.java:538) @ com.fasterxml.jackson.databind.deser.impl.fieldproperty.deserializeandset(fieldproperty.java:106) @ com.fasterxml.jackson.databind.deser.beandeserializer.vanilladeserialize(beandeserializer.java:242) @ com.fasterxml.jackson.databind.deser.beandeserializer.deserialize(beandeserializer.java:118) @ com.fasterxml.jackson.databind.objectmapper._readmapandclose(objectmapper.java:3051) @ com.fasterxml.jackson.databind.objectmapper.readvalue(objectmapper.java:2146) @ com.kube.websocketserver.kubewebsocketserver.onmessage(kubewebsocketserver.java:80) @ org.java_websocket.server.websocketserver.onwebsocketmessage(websocketserver.java:469) @ org.java_websocket.websocketimpl.decodeframes(websocketimpl.java:368) @ org.java_websocket.websocketimpl.decode(websocketimpl.java:157) @ org.java_websocket.server.websocketserver$websocketworker.run(websocketserver.java:657) 

this how im reading message.

hostevent = mapper.readvalue(message,hosteventobject.class); 

this hosteventobject class.

public class hosteventobject {  public static final string messagetype_subscription = "eventsubscription"; public static final string messagetype_eventfired = "eventfired"; public static final string messagetype_fireevent = "fireevent";  @jsonproperty("apiversion") private string apiversion;  @jsonproperty("eventtime") private string eventtime;  @jsonproperty("messagetype") public string messagetype;  @jsonproperty("messagedata") public jsonobject messagedata; } 

below given json string message.

  {    messagetype: "eventsubscription",    messagedata: {        eventid: ["test1","test2"]    }  } 

why getting exception? have read similar questions not making mistakes of spelling nor can ignore property. please advice.

messagedata of type jsonobject doesn't have field called eventid. possibly meant put different class here?

this json

 messagedata: {    eventid: ["test1","test2"]  } 

which requires datatype message data has eventid field kind of list / set / array or other collection of strings . have -

 @jsonproperty("messagedata")  public jsonobject messagedata; 

update looks there jackson module json org: see https://github.com/fasterxml/jackson-datatype-json-org. register module can use :-

 objectmapper mapper = new objectmapper();  mapper.registermodule(new jsonorgmodule()); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -