Skip to content

Conversation

@etrandafir93
Copy link

@etrandafir93 etrandafir93 commented Jan 17, 2026

Some Avro-specific fields will make the ContractVerifierObjectMapper when it tries to map the actual intercepted message to JSON, before performing the relevant assertions on it.

Ignoring these fields will fix the issue, and it won't affect the JSON assertions.

closes #2402

relates to spring-cloudgh-2402

Signed-off-by: Emanuel Trandafir <emanueltrandafir1993@gmail.com>
closes spring-cloudgh-2402

Signed-off-by: Emanuel Trandafir <emanueltrandafir1993@gmail.com>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.12.1</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to a property

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed now 👌🏼

public ContractVerifierObjectMapper() {
this.objectMapper = new JsonMapper();
public ContractVerifierObjectMapper(JsonMapper mapper) {
this.objectMapper = usesAvro() ? ignoreAvroFields(mapper) : mapper;
Copy link
Contributor

@marcingrzejszczak marcingrzejszczak Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about one thing though. Now we have Avro. What if in the future we will need to support more things? I don't like that we're leaking Avro in this class.

I think this code should be moved to NoOpContractVerifierAutoConfiguration and have a conditional on class there, where in case of avro being present would create a proper ContractVerifierObjectMapper.

WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcingrzejszczak yes, it makes sense. I've re-arranged things a bit, now.
Can you please take a look?

@etrandafir93 etrandafir93 force-pushed the contracte_verifier_avro branch from 3a6ae0f to 9001803 Compare January 19, 2026 18:27
closes spring-cloudgh-2402

Signed-off-by: Emanuel Trandafir <emanueltrandafir1993@gmail.com>
@etrandafir93 etrandafir93 force-pushed the contracte_verifier_avro branch from 9001803 to a74018f Compare January 19, 2026 18:34
return new ContractVerifierObjectMapper(mapper);
}

@Bean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would wrap these Avro related classes in a nested AvroContractVerifierObjectMapperConfiguration

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created the new -nested - config class now

closes spring-cloudgh-2402

Signed-off-by: Emanuel Trandafir <emanueltrandafir1993@gmail.com>
@Bean
@ConditionalOnMissingBean
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.apache.avro.specific.SpecificRecordBase")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a cass you can add this as an optional dependency and then normally reference it. Then same below - you could use the class reference instead of doing Class.forName()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it now, it looks much better 👍🏼
It won't fail because of the SpecificRecordBase import if we don't load the nested config class, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, since we have textual class on conditional on class here the class will not be loaded. If the class is missing the rest won't be read.

closes spring-cloudgh-2402

Signed-off-by: Emanuel Trandafir <emanueltrandafir1993@gmail.com>
@Bean
@ConditionalOnMissingBean
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.apache.avro.specific.SpecificRecordBase")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, since we have textual class on conditional on class here the class will not be loaded. If the class is missing the rest won't be read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ContractVerifierObjectMapper fails for Avro-generated objects

3 participants