public DocumentDefinition<Simple> simpleProperty() { return new JsonDocumentDefinition<Simple>(){{ mapping(Simple.class).with( property("myProperty") ); }}; }
public DocumentDefinition<NestedObjects> nestedObjects2() { return new JsonDocumentDefinition<NestedObjects>() { { mapping(NestedObjects.class).with( simple("first"), simple("second") ); } private NamedObject<Simple> simple(String aName) { return object(aName, Simple.class).with( property("myProperty") ); } }; }
public DocumentDefinition<Typed> jsonTypedProperties() { return new JsonDocumentDefinition<Typed>(){{ mapping(Typed.class).with( number("integer", Integer.class), number("float", Float.class), bool("boolean") ); }}; }
public DocumentDefinition<SimplePropertyArray> simplePropertyArraysWithShortcut() { return new JsonDocumentDefinition<SimplePropertyArray>(){{ mapping(SimplePropertyArray.class).with( property("someProperty"), array("strings").of(String.class) ); }}; }
public DocumentDefinition<SimplePropertyArray> simplePropertyArrays() { return new JsonDocumentDefinition<SimplePropertyArray>(){{ mapping(SimplePropertyArray.class).with( property("someProperty"), array("strings").of( property(String.class) ) ); }}; }
public DocumentDefinition<ArrayOfArrays> arraysOfArrays() { return new JsonDocumentDefinition<ArrayOfArrays>(){{ mapping(ArrayOfArrays.class).with( array("arrays").of( array().of(String.class) ) ); }}; }
public DocumentDefinition<NestedObjects> nestedObjects1() { return new JsonDocumentDefinition<NestedObjects>() {{ mapping(NestedObjects.class).with( object("first", Simple.class).with( property("myProperty") ), object("second", Simple.class).with( property("myProperty") ) ); }}; }
public DocumentDefinition<ObjectArrays> objectArrays() { return new JsonDocumentDefinition<ObjectArrays>() {{ mapping(ObjectArrays.class).with( property("someProperty"), array("simples").of( object(Simple.class).with( property("myProperty") ) ) ); }}; }
public DocumentDefinition<Immutable> immutableRootTypes() { return new JsonDocumentDefinition<Immutable>(){{ converting(Interface.class).to(Immutable.class).using( new Converter<Interface, Immutable>(){ @Override public Immutable convert(Interface aFrom) { return new Immutable(aFrom.getFirst(), aFrom.getSecond()); } } ); mapping(Immutable.class).via(Interface.class).with( property("first"), property("second") ); }}; }
public DocumentDefinition<Immutable> intermediateRootTypeWithNoCommonHierarchy() { // a converter that can convert from Uncommon to Immutable // this could be written inline in the document definition, // and, with Java8 lambdas, could be quite succinct. final Converter<Uncommon, Immutable> uncommonToImmutable = new Converter<Uncommon, Immutable>() { public Immutable convert(Uncommon aFrom) { return new Immutable(aFrom.getFirst(), aFrom.getSecond()); } }; return new JsonDocumentDefinition<Immutable>(){{ converting(Uncommon.class).to(Immutable.class).using(uncommonToImmutable); mapping(Immutable.class).via(Uncommon.class).with( property("first"), property("second") ); }}; }
public DocumentDefinition<MixedTypes> mixedTypeHandling() { return new JsonDocumentDefinition<MixedTypes>(){{ mapping(MixedTypes.class).with( property("firstProperty"), object("firstObject", Simple.class).with( property("myProperty") ), object("secondObject", Simple.class).with( property("myProperty") ), property("secondProperty") ); }}; }
/** * { * "first-property": { * "myProperty":"first value" * }, * "second-property": { * "myProperty":"second value" * } * } */ public DocumentDefinition<NestedObjects> aliasedMethodNames() { return new JsonDocumentDefinition<NestedObjects>() {{ mapping(NestedObjects.class).with( object(alias("first-property", "first"), Simple.class).with( property("myProperty") ), object(alias("second-property", "second"), Simple.class).with( property("myProperty") ) ); }}; }
mapping(Immutables.class).with(