SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.overbaard.review.tool._temp;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import javax.json.bind.JsonbBuilder;
  7. import javax.json.bind.JsonbConfig;
  8. import javax.json.bind.annotation.JsonbTypeSerializer;
  9. import javax.json.bind.serializer.JsonbSerializer;
  10. import javax.json.bind.serializer.SerializationContext;
  11. import javax.json.stream.JsonGenerator;
  12.  
  13. import org.junit.jupiter.api.Test;
  14.  
  15. import io.quarkus.test.junit.QuarkusTest;
  16.  
  17. /**
  18.  * @author <a href="mailto:kabir.khan@jboss.com">Kabir Khan</a>
  19.  */
  20. // @QuarkusTest
  21. public class __ThrowawayTest {
  22.     @Test
  23.     public void testSimpleEntity() {
  24.         Organisation organisation = new Organisation("My org");
  25.         String s = JsonbBuilder.create().toJson(organisation);
  26.         System.out.println(s);
  27.     }
  28.  
  29.     @JsonbTypeSerializer(MySerializer.class)
  30.     public static class Organisation {
  31.         private String name;
  32.  
  33.         public Organisation(String name) {
  34.             this.name = name;
  35.         }
  36.  
  37.         public String getName() {
  38.             return name;
  39.         }
  40.  
  41.         public void setName(String name) {
  42.             this.name = name;
  43.         }
  44.     }
  45.  
  46.     public static class MySerializer implements JsonbSerializer<Organisation> {
  47.         @Override
  48.         public void serialize(Organisation obj, JsonGenerator generator, SerializationContext ctx) {
  49.             generator.writeStartObject();
  50.             generator.write("name", obj.getName());
  51.             generator.writeEnd();
  52.         }
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top