Class DelegatingJsonValue

  • All Implemented Interfaces:
    JsonValue

    public abstract class DelegatingJsonValue
    extends java.lang.Object
    implements JsonValue
    An abstract JsonValue object which just delegates to another JsonValue object. It's meant to fix the lack of native support for the delagate pattern in Java.

    You can use it to compose complex JsonValue Objects or Arrays and give the result a proper name.

    Example

    
     public final class Person extends DelegatingJsonValue
     {
         public Person(String firstName, String lastName, int age)
         {
             super(new Object(
                 new Member("@class", "person"),
                 new Member("firstname", firstName),
                 new Member("lastname", lastName),
                 new Member("age", age)));
         }
     }
     

    The following code results in a valid a valid JsonValue object:

    new Person("John", "Doe", 23)
    • Constructor Detail

      • DelegatingJsonValue

        public DelegatingJsonValue​(JsonValue delegate)
    • Method Detail

      • serialize

        public final void serialize​(JsonSink jsonSink)
                             throws java.io.IOException
        Specified by:
        serialize in interface JsonValue
        Throws:
        java.io.IOException