This repository was archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Afterburner doesn't handle annotation @JsonRawValue while serializing to JSON #38
Copy link
Copy link
Closed
Milestone
Description
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));
}
}
Metadata
Metadata
Assignees
Labels
No labels