Skip to content

JSON Pointer inconsistent when serializing first element of an array #1154

@itineric

Description

@itineric

During serialization, when using a custom serializer, the JsonPointer is inconsistent when serializing the first element. Instead of having /myList/0 we get /myList

This happens because we enter this part of code : https://github.com/FasterXML/jackson-core/blob/2.17/src/main/java/com/fasterxml/jackson/core/JsonPointer.java#L212

The call stack looks like this, the Object received in my CustomSerializer.serialize method is the first element of my array.

JsonPointer.forPath(JsonStreamContext, boolean) line: 215	
JsonWriteContext(JsonStreamContext).pathAsPointer() line: 279	
CustomSerializer.serializeWithType(Object, JsonGenerator, SerializerProvider, TypeSerializer)
IndexedListSerializer.serializeTypedContents(List<?>, JsonGenerator, SerializerProvider) line: 181	
IndexedListSerializer.serializeContents(List<?>, JsonGenerator, SerializerProvider) line: 92	
IndexedListSerializer.serialize(List<?>, JsonGenerator, SerializerProvider) line: 79	

Additional info: the problem seems to be the _index of _writeContext of JsonGenerator instance which is -1 but should be 0 at that time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    need-test-caseNeeds a test case (unit test or such) to proceed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions