On Thursday, July 29, 2021 at 10:36:44 AM UTC-7 [email protected] wrote: > Version of libraries: > * google-api-services-logging: v2-rev20210709-1.32.1 > * jackson-core/databind/annotations: 2.11.2 > * Not using Spring or Lombok > > I'm attempting to deserialize > com.google.api.services.logging.v2.model.LogEntry using ObjectMapper > however I'm seeing this exception. It's trying to map the subclasses in > LogEntry to a Map and fails. Note this is just an example of it trying to > map the operation section of the JSON. If it attempts it for the other > subclasses (depending on the JSON logs) its the same exception albeit with > the different fields. > > Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not > set com.google.api.services.logging.v2.model.LogEntryOperation field > com.google.api.services.logging.v2.model.LogEntry.operation to > java.util.LinkedHashMap (through reference chain: > com.google.api.services.logging.v2.model.LogEntry["operation"]) at > com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:397) > at > com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:356) > > at > com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase.wrapAndThrow(ContainerDeserializerBase.java:181) > > at > com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:552) > > at
com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:377) > at > com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:29) > > at > com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4524) > > at > com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3503) > at > com.abc.logging.data.parsing.LogEntryParser.parse(LogEntryParser.java:81) > ... 28 more Caused by: java.lang.IllegalArgumentException: Can not set > com.google.api.services.logging.v2.model.LogEntryOperation field > com.google.api.services.logging.v2.model.LogEntry.operation to > java.util.LinkedHashMap at > java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) > > at > java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) > > at > java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) > > at java.base/java.lang.reflect.Field.set(Field.java:780) at > com.google.api.client.util.FieldInfo.setFieldValue(FieldInfo.java:275) at > com.google.api.client.util.FieldInfo.setValue(FieldInfo.java:231) at > com.google.api.client.util.GenericData.put(GenericData.java:98) at > com.google.api.client.util.GenericData.put(GenericData.java:43) at > com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:547) > > ... 33 more > > Given LogEntry is part of the Google logging v2 library I don't have > access to add annotations but assumed it was fine given it extends > GenericJson. The deserialization is pretty straight forward with: > > byte[] data = jsonString.getBytes(); > ObjectMapper mapper = new ObjectMapper(); > mapper.readValue(new ByteArrayInputStream(data), LogEntry.class); > > I understand Jackson will default to a LinkedHashMap when it doesn't know > what to deserialize to. Given this I attempted to use a mixin class like > so to map these specific subclasses: > This seems to be due to some mismatch in declaration of "operation" field of `LogEntry`; type perhaps being inconsistently defined between underlying field and getter/setter. So it would probably be necessary to see what is going in there. A reproduction with failure -- probably a test project, since it requires a dependency to a 3rd party library -- would make sense, if you can isolate it. And then filing an issue (or sending a link on this discussion). I can have a look. Mix-ins you included would not be relevant as the issue is specifically wrt `operation`, but another mix-in might be necessary. -+ Tatu +- -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/2336d150-62dc-4a8a-95da-d5d995783acbn%40googlegroups.com.
