This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d68ed5e
commit bda2f9b
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/com/fasterxml/jackson/module/afterburner/ser/JsonAppendTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.fasterxml.jackson.module.afterburner.ser; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.annotation.JsonAppend; | ||
import com.fasterxml.jackson.databind.cfg.MapperConfig; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedClass; | ||
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition; | ||
import com.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter; | ||
import com.fasterxml.jackson.databind.util.Annotations; | ||
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase; | ||
|
||
// most for [module-afterburner#57] | ||
public class JsonAppendTest extends AfterburnerTestBase | ||
{ | ||
@JsonAppend(props = @JsonAppend.Prop(name = "virtual", value = MyVirtualPropertyWriter.class)) | ||
public static class Pojo { | ||
public final String name; | ||
public Pojo(String name) { | ||
this.name = name; | ||
} | ||
} | ||
|
||
public static class MyVirtualPropertyWriter extends VirtualBeanPropertyWriter { | ||
protected MyVirtualPropertyWriter() { } | ||
|
||
protected MyVirtualPropertyWriter(BeanPropertyDefinition propDef, Annotations contextAnnotations, | ||
JavaType declaredType) { | ||
super(propDef, contextAnnotations, declaredType); | ||
} | ||
@Override | ||
protected Object value(Object bean, JsonGenerator g, SerializerProvider prov) throws Exception { | ||
return "bar"; | ||
} | ||
@Override | ||
public VirtualBeanPropertyWriter withConfig(MapperConfig<?> config, AnnotatedClass declaringClass, | ||
BeanPropertyDefinition propDef, JavaType type) { | ||
return new MyVirtualPropertyWriter(propDef, declaringClass.getAnnotations(), type); | ||
} | ||
} | ||
|
||
public void testSimpleAppend() throws Exception | ||
{ | ||
ObjectMapper mapper = mapperWithModule(); | ||
// ObjectMapper mapper = new ObjectMapper(); | ||
String json = mapper.writeValueAsString(new Pojo("foo")); | ||
assertEquals("{\"name\":\"foo\",\"virtual\":\"bar\"}", json); | ||
} | ||
} |