Created
April 12, 2019 09:04
-
-
Save kabir/e99924fbd79fdc6e4e0520ff16aefe56 to your computer and use it in GitHub Desktop.
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
package org.overbaard.review.tool._temp; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.json.bind.JsonbBuilder; | |
import javax.json.bind.JsonbConfig; | |
import javax.json.bind.annotation.JsonbTypeSerializer; | |
import javax.json.bind.serializer.JsonbSerializer; | |
import javax.json.bind.serializer.SerializationContext; | |
import javax.json.stream.JsonGenerator; | |
import org.junit.jupiter.api.Test; | |
import io.quarkus.test.junit.QuarkusTest; | |
/** | |
* @author <a href="mailto:kabir.khan@jboss.com">Kabir Khan</a> | |
*/ | |
// @QuarkusTest | |
public class __ThrowawayTest { | |
@Test | |
public void testSimpleEntity() { | |
Organisation organisation = new Organisation("My org"); | |
String s = JsonbBuilder.create().toJson(organisation); | |
System.out.println(s); | |
} | |
@JsonbTypeSerializer(MySerializer.class) | |
public static class Organisation { | |
private String name; | |
public Organisation(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
} | |
public static class MySerializer implements JsonbSerializer<Organisation> { | |
@Override | |
public void serialize(Organisation obj, JsonGenerator generator, SerializationContext ctx) { | |
generator.writeStartObject(); | |
generator.write("name", obj.getName()); | |
generator.writeEnd(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment