- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.4k
 
Closed
Milestone
Description
public static class Bean {
	public @JsonUnwrapped Optional<String> value;
}
var b = new Bean();
b.value = Optional.of("str");
jackson.writeValueAsString(b);com.fasterxml.jackson.core.JsonGenerationException: Can not write a string, expecting field name (context: Object)
	at [email protected]/com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:2080)
	at [email protected]/com.fasterxml.jackson.core.json.JsonGeneratorImpl._reportCantWriteValueExpectName(JsonGeneratorImpl.java:248)
	at [email protected]/com.fasterxml.jackson.core.json.JsonGeneratorImpl._verifyPrettyValueWrite(JsonGeneratorImpl.java:238)
	at [email protected]/com.fasterxml.jackson.core.json.WriterBasedJsonGenerator._verifyValueWrite(WriterBasedJsonGenerator.java:894)
	at [email protected]/com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeString(WriterBasedJsonGenerator.java:400)
	at [email protected]/com.fasterxml.jackson.databind.ser.std.StringSerializer.serialize(StringSerializer.java:41)
	at [email protected]/com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer.serialize(ReferenceTypeSerializer.java:381)
	at [email protected]/com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter.serializeAsField(UnwrappingBeanPropertyWriter.java:127)
	at [email protected]/com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:722)
	at [email protected]/com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
	at [email protected]/com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
	at [email protected]/com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
	at [email protected]/com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:4094)
	at [email protected]/com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3404)
jackson-databind/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java
Line 300 in f315f1b
| return (_unwrapper != null); | 
I think change the expression to
_unwrapper != null && _valueSerializer.isUnwrappingSerializer()may fix it, but _valueSerializer can be null here. Hoping anyone familiar with this can fix it.
Metadata
Metadata
Assignees
Labels
No labels