You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
The @ JsonRawValue annotation in the test below is ignored, and its quoted and treated like a string. Does the library support raw serialization? If yes, how would one go about it?
import com.fasterxml.jackson.annotation.JsonRawValue;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import java.io.StringWriter;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class JSONUtilTest
{
class SerializableObject
{
@JsonRawValue
String value;
public String getValue()
{
return value;
}
}
public String genJSON(ObjectMapper mapper, Object obj) throws Exception
{
StringWriter sw = new StringWriter();
String dataValue;
JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(sw);
// start top level object
jsonGenerator.writeStartObject();
jsonGenerator.writeFieldName("test");
dataValue = mapper.writeValueAsString(obj);
jsonGenerator.writeRawValue(dataValue);
// end top level object
jsonGenerator.writeEndObject();
jsonGenerator.close();
sw.close();
String actual = sw.getBuffer().toString();
return actual;
}
@Test
public void testAfterBurner() throws Exception
{
SerializableObject so = new SerializableObject();
so.value = "{ k1:1, k2:2 }";
ObjectMapper mapper1 = new ObjectMapper();
assertEquals("{\"test\":{\"value\":{ k1:1, k2:2 }}}", genJSON(mapper1, so));
ObjectMapper mapper2 = new ObjectMapper();
mapper2.registerModule(new AfterburnerModule());
// Afterburner bug, it ignores the JsonRawValue annotation, and quotes the
// JsonRawValue, treating like a string. Afterburner code seems to be
// missing a raw serializer.
assertEquals("{\"test\":{\"value\":\"{ k1:1, k2:2 }\"}}",
genJSON(mapper2, so));
}
}
The text was updated successfully, but these errors were encountered:
I think raw values should work same with Afterburner as they would do without; that is, work if underlying format supports it via JsonGenerator. So this sounds like a bug.
Yep. I'm working around it in the SerializerModifier, when it checks for custom serializers.
protected boolean isDefaultButNotRawSerializer(SerializationConfig config,
JsonSerializer<?> ser)
{
boolean ret = ClassUtil.isJacksonStdImpl(ser);
// hack to force afterburner to ignore Raw Serializers
boolean ret2 = ser instanceof RawSerializer;
return ret && !ret2;
}
The @ JsonRawValue annotation in the test below is ignored, and its quoted and treated like a string. Does the library support raw serialization? If yes, how would one go about it?
The text was updated successfully, but these errors were encountered: