Package com.github.nmorel.gwtjackson.client

Examples of com.github.nmorel.gwtjackson.client.JsonDeserializationContext


    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() );
View Full Code Here


    public void testDeserializeNullValue() {
        assertNull( deserialize( "null" ) );
    }

    protected T deserialize( String value ) {
        JsonDeserializationContext ctx = new Builder().build();
        JsonReader reader = ctx.newJsonReader( value );
        return createDeserializer().deserialize( reader, ctx );
    }
View Full Code Here

    public void testDeserializeNullValue() {
        assertNull( deserialize( null ) );
    }

    protected T deserialize( String value ) {
        JsonDeserializationContext ctx = new Builder().build();
        return createDeserializer().deserialize( value, ctx );
    }
View Full Code Here

TOP

Related Classes of com.github.nmorel.gwtjackson.client.JsonDeserializationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.