jackson-modules-base icon indicating copy to clipboard operation
jackson-modules-base copied to clipboard

ObjectMapper add Module "jackson-module-afterburner" java.lang.IllegalStateException: Multiple definitions of method getBody found

Open bxvs888 opened this issue 1 month ago • 4 comments

result :

Jackson version: 3.0.1 fail

interface A:


public interface A<T> {

	 T getBody();
}

implements


public class MD implements A<String> {

	private String body;
	/**
	 * @return
	 */

	@Override
	public String getBody() {
		return body;
	}
}

convert toJSON:


	public static void main(String[] args) {


		MD md = new MD();

		ObjectMapper objectMapper =
				JsonMapper.builder()
				 .addModule(new AfterburnerModule())
					 .build();
		String json = objectMapper.writeValueAsString(md);
		System.out.println(json);
	}

Exception :


Exception in thread "main" java.lang.IllegalStateException: Multiple definitions of method getBody found
	at tools.jackson.module.afterburner.ser.PropertyAccessorCollector$SingleMethodStackManipulation.invocationOperation(PropertyAccessorCollector.java:338)
	at tools.jackson.module.afterburner.ser.PropertyAccessorCollector$AbstractSinglePropStackManipulation.apply(PropertyAccessorCollector.java:247)
	at net.bytebuddy.implementation.bytecode.StackManipulation$Compound.apply(StackManipulation.java:243)
	at tools.jackson.module.afterburner.util.bytebuddy.AbstractDelegatingAppender.apply(AbstractDelegatingAppender.java:56)
	at net.bytebuddy.implementation.bytecode.ByteCodeAppender$Compound.apply(ByteCodeAppender.java:158)
	at net.bytebuddy.dynamic.scaffold.TypeWriter$MethodPool$Record$ForDefinedMethod$WithBody.applyCode(TypeWriter.java:732)
	at net.bytebuddy.dynamic.scaffold.TypeWriter$MethodPool$Record$ForDefinedMethod$WithBody.applyBody(TypeWriter.java:717)
	at net.bytebuddy.dynamic.scaffold.TypeWriter$MethodPool$Record$ForDefinedMethod.apply(TypeWriter.java:624)
	at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForCreation.create(TypeWriter.java:6134)
	at net.bytebuddy.dynamic.scaffold.TypeWriter$Default.make(TypeWriter.java:2246)
	at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$UsingTypeWriter.make(DynamicType.java:4085)
	at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:3769)
	at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$Delegator.make(DynamicType.java:4021)
	at tools.jackson.module.afterburner.ser.PropertyAccessorCollector.generateAccessorClass(PropertyAccessorCollector.java:165)
	at tools.jackson.module.afterburner.ser.PropertyAccessorCollector.findAccessor(PropertyAccessorCollector.java:113)
	at tools.jackson.module.afterburner.ser.ABSerializerModifier.changeProperties(ABSerializerModifier.java:64)
	at tools.jackson.databind.ser.BeanSerializerFactory.constructBeanOrAddOnSerializer(BeanSerializerFactory.java:338)
	at tools.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:249)
	at tools.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:182)
	at tools.jackson.databind.SerializationContext._createAndCacheUntypedSerializer(SerializationContext.java:968)
	at tools.jackson.databind.SerializationContext.findValueSerializer(SerializationContext.java:774)
	at tools.jackson.databind.SerializationContext.findTypedValueSerializer(SerializationContext.java:586)
	at tools.jackson.databind.ser.SerializationContextExt.serializeValue(SerializationContextExt.java:297)
	at tools.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:1879)
	at tools.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:1823)
	at JsonTest.main(JsonTest.java:45)

bxvs888 avatar Oct 24 '25 04:10 bxvs888

I assume this would also fail in 2.x (like 2.20.0)? (not sure if it'd be easy to check -- I can try reproduce)

cowtowncoder avatar Oct 25 '25 00:10 cowtowncoder

As per #315, works on 2.x...

cowtowncoder avatar Oct 25 '25 01:10 cowtowncoder

Hmmh. Can not reproduce in 3.x either, see:

https://github.com/FasterXML/jackson-modules-base/blob/3.x/afterburner/src/test/java/tools/jackson/module/afterburner/tofix/AfterburnerGenericInterface314Test.java

cowtowncoder avatar Oct 25 '25 01:10 cowtowncoder

Need a reproduction of failure: my attempt to use given example not successful.

cowtowncoder avatar Oct 31 '25 23:10 cowtowncoder