Skip to content
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

StackTraceElementDeserializer not working if field visibility changed #1794

Closed
dsingley opened this issue Oct 16, 2017 · 1 comment
Closed
Milestone

Comments

@dsingley
Copy link

exception when deserializing annotated StackTraceElement[] field:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "declaringClass" (class java.lang.StackTraceElement), not marked as ignorable
        at [Source: N/A; line: -1, column: -1] (through reference chain: com.volumeintegration.va.messaging.ErrorObject["stackTrace"]->Object[][0]->java.lang.StackTraceElement["declaringClass"])
       at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62)
       at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:833)
       at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1096)
       at com.fasterxml.jackson.databind.deser.std.StackTraceElementDeserializer.deserialize(StackTraceElementDeserializer.java:52)
       at com.fasterxml.jackson.databind.deser.std.StackTraceElementDeserializer.deserialize(StackTraceElementDeserializer.java:11)
       at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:196)
       at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:20)
       at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490)
       at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
       at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)
       at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
       at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3761)
       at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2090)
       at com.fasterxml.jackson.databind.ObjectMapper.treeToValue(ObjectMapper.java:2587)

experiencing on version 2.8.2, reproduced with 2.8.10 and 2.9.2

works fine in tests that serialize directly to and from a String, but fails when serialized to a byte[], first deserailized to a JsonNode and then from a JsonNode to the original object class

example test code:
https://groups.google.com/d/msg/jackson-user/buIEhJhB1xk/Zdg4_cTdAAAJ

@cowtowncoder
Copy link
Member

Ah. At first I was unable to reproduce until I noticed:

mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);

which explains the issue: non-public field is found, serialized. However, you are still using standard Jackson StackTraceElementDeserializer that only expects public properties normally serialized.
(that annotation is actually redundant and may be removed, at least in this example).
I guess there are multiple ways of viewing this (including whether there should be explicit serializer, instead of relying on standard Bean handling which can break on new JDKs). But since it's just one field I think I'll patch deserializer to make this case work.

@cowtowncoder cowtowncoder added this to the 2.9.3 milestone Nov 1, 2017
@cowtowncoder cowtowncoder changed the title @JsonDeserialize(contentUsing = StackTraceElementDeserializer.class) not working StackTraceElementDeserializer not working if field visibility changed Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants