private JsonDeserializationContext createDeserializationContext() {
return new JsonDeserializationContext.Builder().acceptSingleValueAsArray( true ).build();
}
public void testDeserialize() {
JsonDeserializationContext context = createDeserializationContext();
// first with simple scalar types (numbers), with collections
List<Integer> ints = ListJsonDeserializer.newInstance( IntegerJsonDeserializer.getInstance() ).deserialize( context
.newJsonReader( "4" ), context );
assertEquals( 1, ints.size() );
assertEquals( Integer.valueOf( 4 ), ints.get( 0 ) );
List<String> strings = ListJsonDeserializer.newInstance( StringJsonDeserializer.getInstance() ).deserialize( context
.newJsonReader( "\"abc\"" ), context );
assertEquals( 1, strings.size() );
assertEquals( "abc", strings.get( 0 ) );
// and arrays:
int[] intArray = PrimitiveIntegerArrayJsonDeserializer.getInstance().deserialize( context.newJsonReader( "-7" ), context );
assertEquals( 1, intArray.length );
assertEquals( -7, intArray[0] );
String[] stringArray = ArrayJsonDeserializer.newInstance( StringJsonDeserializer.getInstance(), new ArrayCreator<String>() {
@Override
public String[] create( int length ) {
return new String[length];
}
} ).deserialize( context.newJsonReader( "\"xyz\"" ), context );
assertEquals( 1, stringArray.length );
assertEquals( "xyz", stringArray[0] );
// and then with Beans:
List<XBean> xbeanList = ListXBeanReader.INSTANCE.read( "{\"x\":4}", createDeserializationContext() );