Package flexjson.transformer

Examples of flexjson.transformer.DateTransformer


     */
    @ManyToOne
    private Userinfo userName;

    public String toJson() {
        return new JSONSerializer().exclude("*.class").transform(new DateTransformer("MM/dd/yyyy"), Date.class).serialize(this);
    }
View Full Code Here


    public static Todo fromJsonToTodo(String json) {
        return new JSONDeserializer<Todo>().use(null, Todo.class).deserialize(json);
    }

    public static String toJsonArray(Collection<Todo> collection) {
        return new JSONSerializer().exclude("*.class").transform(new DateTransformer("MM/dd/yyyy"), Date.class).serialize(collection);
    }
View Full Code Here

        assertAttributeMissing("class", json);
    }

    @Test
    public void testDateTransforming() {
        String json = new JSONSerializer().transform(new DateTransformer("yyyy-MM-dd"), "birthdate").serialize(charlie);

        assertAttribute("birthdate", json);
        assertStringValue("1988-11-23", json);
    }
View Full Code Here

    @Test
    public void testDefaultDateFormats() throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat("MM/dd/yy");
        Person charlie = new Person("Charlie", "Hubbard", new Date(), null, null);
        charlie.setBirthdate(df.parse("03/21/76"));
        DateTransformer transformer = new DateTransformer( df.toPattern() );

        String json = new JSONSerializer().transform(transformer, "birthdate").serialize(charlie);
        Person newUser = new JSONDeserializer<Person>().deserialize(json);

        assertEquals( charlie.getBirthdate(), newUser.getBirthdate() );
        assertEquals( "03/21/76", df.format(newUser.getBirthdate()) );

        String pattern = "yyyy-MM-dd hh:mm:ss";

        json = new JSONSerializer().transform( new DateTransformer( pattern ), Date.class ).serialize(charlie);
        Person user = new JSONDeserializer<Person>().use("birthdate", new DateObjectFactory().add(pattern) ).deserialize(json);

        assertEquals( charlie.getBirthdate(), user.getBirthdate() );
        assertEquals( "03/21/76", df.format( user.getBirthdate() ) );

        DateObjectFactory.addDefaultFormat( pattern );
        json = new JSONSerializer().transform( new DateTransformer( pattern ), Date.class ).serialize(charlie);
        user = new JSONDeserializer<Person>().deserialize(json);

        assertEquals( charlie.getBirthdate(), user.getBirthdate() );
        assertEquals( "03/21/76", df.format( user.getBirthdate() ) );
    }
View Full Code Here

    @Test
    public void testDateTransforming() throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
        Person charlie = new Person("Charlie", "Hubbard", new Date(), null, null);
        charlie.setBirthdate(df.parse("2009/01/02"));
        DateTransformer transformer = new DateTransformer("yyyy/MM/dd");

        String json = new JSONSerializer().transform(transformer, "birthdate").serialize(charlie);
        Person newUser = new JSONDeserializer<Person>().use(transformer, "birthdate").deserialize(json);
        assertEquals( charlie.getBirthdate(), newUser.getBirthdate() );
        assertEquals( "2009/01/02", df.format(newUser.getBirthdate()) );
View Full Code Here

TOP

Related Classes of flexjson.transformer.DateTransformer

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.