jackson-databind: Duplicate creator property "b" (index 0 vs 1) on simple java record

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Using jackson-databind 2.18.3 and a java record like:

    record Dummy(
            
            @JsonProperty(value = "a", access = JsonProperty.Access.READ_ONLY) String a,

            @JsonProperty(value = "b", access = JsonProperty.Access.READ_ONLY) String b) {
    }
    

then reading a value fails with:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Duplicate creator property "b" (index 0 vs 1) for type `com.cgi.tf.openapi.test.JacksonTest$Dummy` 
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1]
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:62)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:269)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:151)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:471)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:415)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:317)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)

Changing most things about the recod causes it to work . This is a minimised version of a fuller realistic case.

Version Information

No response

Reproduction

<-- Any of the following

  1. Brief code sample/snippet: include here in preformatted/code section
  2. Longer example stored somewhere else (diff repo, snippet), add a link
  3. Textual explanation: include here –>
// Your code here

Expected behavior

No response

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (17 by maintainers)

Commits related to this issue

Most upvoted comments

The fix is included in 2.19.0-rc2 released yesterday, fwtw. Will be in 2.19.0 as well as eventual 2.18.4

Also: MapperFeature.INVERSE_READ_WRITE_ACCESS is added via #2951 which allows “swapping” meaning of READ_ONLY and WRITE_ONLY – included for 2.19. This might be handy setting as well.

@yihtserns Fair. At any rate, underlying issue from Jackson perspective is resolved as I understand. Let’s hope it will help user with their goal, whatever it actually is 😃

@cowtowncoder not entirely sure about that since I can see a few different ways to interpret his statements… 😓

I can’t afford to spend time trying to get on the same page as him, so decided to do a “here’s the outcome, please check for yourself #SelfServicePlease”.

@yihtserns It seemed to be his use of READ_ONLY itself was incorrect (needs to use WRITE_ONLY).

Added test; could see where name duplication is but not where it comes from. Yet.

Adding test via #5061 – this is tricky as almost all the way parameters “a” and “b” are passed just fine – until at some point there are two "b"s. Very odd…