Deserializing JSON with Jackson - Why JsonMappingException “No suitable constructor”?

The error messages says it all, your ProtocolContainer does not have a default constructor so Jackson is unable to create an instance of it. (Since the only current way of creating a ProtocolContainer is by passing in a DataPacket. ).

Yes, I added an empty constructor. Its weird, cause I got another error before, when I had an empty constructor... Anyways, this particular issue is resolved... no I have to deal with the "__type" thing that . NET adds on serialization... – Ted Dec 3 at 12:05 Hmm, so the error is back, sort of.

Now I get this: JsonMappingException: Can not instantiate value of type simple type, class MyPackage. ProtocolContainer from JSON String; no single-String constructor/factory method. If I add a constructor that takes a String, then no error but the Object is "empty"... I don't think it should be necessary to add implementation support in the constructor... – Ted Dec 3 at 16:39.

In this case, you could add @JsonCreator annotation to constructor; and there are two ways it could be done: If you only odd that annotation, then the whole matching JSON is first bound to type of the only argument (`DataPacket'). I assume you do not want to do that If you also add @JsonProperty annotation before the argument, then JSON property matching that name is passed to constructor (annotation is mandatory because Java byte code does NOT contain name of method or constructor arguments) -- I suspect you want @JsonProperty("SubPacket") This works if necessary information for constructor comes from JSON. If not, you do need to add alternate no-arg constructor.By the way, the error message does sound wrong in this case; it should only be given if JSON data matching expected value if a JSON String.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions