@Test public void testInt() throws Exception { EntityMarshaller<Int> marshaller = createEntityMarshaller(Int.class); Json.Object object = marshaller.marshall( new Int() { { this.literal = 1; this.object = 2; this.nativeArray = new int[] {3, 4}; this.objectArray = new Integer[] {5, 6}; } }); assertJsonObjectWellFormed(object); assertEquals("1", object.get(string("literal")).toString()); Int instance = marshaller.unmarshall(object); assertEquals(1, instance.literal); assertEquals(2, instance.object); assertEquals(2, instance.nativeArray.length); assertEquals(3, instance.nativeArray[0]); assertEquals(4, instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals(5, instance.objectArray[0]); assertEquals(6, instance.objectArray[1]); }
@Test public void testLong() throws Exception { EntityMarshaller<Long> marshaller = createEntityMarshaller(Long.class); Json.Object object = marshaller.marshall( new Long() { { this.literal = 1L; this.object = 2L; this.nativeArray = new long[] {3, 4}; this.objectArray = new java.lang.Long[] {5L, 6L}; } }); assertJsonObjectWellFormed(object); assertEquals("1", object.get(string("literal")).toString()); Long instance = marshaller.unmarshall(object); assertEquals(1, instance.literal); assertEquals(2.0, instance.object); assertEquals(2, instance.nativeArray.length); assertEquals(3, instance.nativeArray[0]); assertEquals(4, instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals(5, instance.objectArray[0]); assertEquals(6, instance.objectArray[1]); }
private void assertJsonObjectWellFormed( Json.Object object, Json.Value one, Json.Value two, Json.Value three, Json.Value four, Json.Value five, Json.Value six) { assertEquals(one, object.get(string("literal"))); assertEquals(two, object.get(string("object"))); Json.Array nativeArray = (Json.Array) object.get(string("nativeArray")); assertEquals(2, nativeArray.size()); assertEquals(three, nativeArray.get(0)); assertEquals(four, nativeArray.get(1)); Json.Array objectArray = (Json.Array) object.get(string("objectArray")); assertEquals(2, objectArray.size()); assertEquals(five, objectArray.get(0)); assertEquals(six, objectArray.get(1)); }