-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonParser#getCodec() is null in a custom JsonDeserializer #4461
Comments
It seems I just should use DeserializationContext to access other registered (de-)serializatiors, isn't it? |
At first I assumed resolution of Could you please share how |
Also, could you try deserializing like below? Below is from @Override
public Leaf deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonNode tree = (JsonNode) jp.readValueAsTree();
Leaf leaf = new Leaf();
leaf.value = tree.get("value").intValue();
return leaf;
} |
Correct and it's strange thing. I'm new to Jackson, I've used some examples from the internet to implement custom deserializers. Examples include line like
Please see this gist: https://gist.github.com/Feniksovich/4711bf5570661c915cd9936f56e0b932
I replaced Stacktracejava.lang.IllegalStateException: No ObjectCodec defined for parser, needed for deserialization
at com.fasterxml.jackson.core.JsonParser._codec(JsonParser.java:2547)
at com.fasterxml.jackson.core.JsonParser.readValueAsTree(JsonParser.java:2541)
at com.feniksovich.lab7.serializers.jackson.PersonSerializationModule$PersonDeserializer.deserialize(PersonSerializationModule.java:33)
at com.feniksovich.lab7.serializers.jackson.PersonSerializationModule$PersonDeserializer.deserialize(PersonSerializationModule.java:29)
at com.fasterxml.jackson.databind.DeserializationContext.readValue(DeserializationContext.java:992)
at com.fasterxml.jackson.databind.DeserializationContext.readValue(DeserializationContext.java:979)
at com.feniksovich.lab7.serializers.jackson.HouseSerializationModule$HouseDeserializer.deserialize(HouseSerializationModule.java:47)
at com.feniksovich.lab7.serializers.jackson.HouseSerializationModule$HouseDeserializer.deserialize(HouseSerializationModule.java:40)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4905)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3848)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3816)
at com.feniksovich.lab7.jackson.JacksonSerializationModulesTest.testHouseSerializationTest(JacksonSerializationModulesTest.java:53)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) However, I just tried to use @Override
public Person deserialize(JsonParser parser, DeserializationContext context) throws IOException {
final JsonNode tree = context.readTree(parser);
// ...
} |
com.fasterxml.jackson.core.JsonParser.getCodec() is null
in a custom JsonDeserializer
Sure, I checked the |
Thank you for your assistance, @JooHyukKim! |
I am hoping that we will have more guidance on how to implement custom modules and de/serializers, eventually. Thank you for the feedback! |
Quick note: ideally, you would never need to call
it should be possible to use
Linkage of So, yes, if at all possible, first look into |
@cowtowncoder, thank you for detailed explanation! I really appreciate prompt feedback from your team. |
Thank you @Feniksovich ! |
Search before asking
Describe the bug
Similar resolved issue: #2038
I keep receive NPE on
JsonParser#getCodec()
in a custom JsonDeserializer when trying to deserialize myHouse
POJO:There are also two registered JsonSerializer/JsonDeserializer for the
Person
andFlat
POJOs and they work fine. But onHouse
POJO deserialization I receive NPE onJsonParser#getCodec()
invoke in the PersonDeserializer (see below).Stacktrace
Version Information
2.17.0
Reproduction
House
object and try to deserialize it.JsonParser#getCodec()
.PersonSerializationModule
FlatSerializationModule
HouseSerializationModule
Expected behavior
Successful deserialization of the
House
object.Additional context
No response
The text was updated successfully, but these errors were encountered: