Search in sources :

Example 1 with ObjectFactory

use of com.serotonin.json.spi.ObjectFactory in project ma-core-public by infiniteautomation.

the class PopulateTest method main.

public static void main(String[] args) throws Exception {
    context = new JsonContext();
    context.addFactory(new ObjectFactory() {

        @Override
        public Object create(JsonValue jsonValue) throws JsonException {
            if (jsonValue.toJsonObject().containsKey("sub1Value"))
                return new Subclass1();
            if (jsonValue.toJsonObject().containsKey("sub2Value"))
                return new Subclass2();
            throw new JsonException("Unknown BaseClass: " + jsonValue);
        }
    }, BaseClass.class);
    test1();
    test2();
}
Also used : JsonException(com.serotonin.json.JsonException) JsonContext(com.serotonin.json.JsonContext) ObjectFactory(com.serotonin.json.spi.ObjectFactory) JsonValue(com.serotonin.json.type.JsonValue)

Aggregations

JsonContext (com.serotonin.json.JsonContext)1 JsonException (com.serotonin.json.JsonException)1 ObjectFactory (com.serotonin.json.spi.ObjectFactory)1 JsonValue (com.serotonin.json.type.JsonValue)1