Package flexjson.mock

Examples of flexjson.mock.Person


        assertEquals( "Charlie", complex.get( "1" ).getSecond().getName() );
    }

    @Test
    public void testArrayType() {
        Person charlie = creator.createCharlie();
        Person ben = creator.createBen();

        Group group = new Group( "brothers", charlie, ben );
        String json = new JSONSerializer().include("people").exclude("*.class").serialize( group );
        Group bro = new JSONDeserializer<Group>().use( null, Group.class ).deserialize( json );

View Full Code Here


        assertEquals( "Ben", jsonP[2].getFirstname() );
    }

    @Test
    public void testDeserializeIntoExistingObject() {
        Person charlie = creator.createCharlie();
        Phone fakePhone = new Phone( PhoneNumberType.MOBILE, "303 555 1234");

        Person charlieClone = new Person( "Chauncy", "Beauregard", null, null, null );
        charlieClone.getPhones().add( fakePhone );
        charlieClone.getHobbies().add("Being Fake");
        charlieClone.getHobbies().add("Assuming Other Identities");

        String json = new JSONSerializer().include("hobbies").exclude("firstname", "lastname").serialize( charlie );
        Person p = new JSONDeserializer<Person>().deserializeInto(json, charlieClone);

        assertSame("Make sure the root object is the exact same reference as the one provided to the factory", charlieClone, p );
        assertEquals( charlieClone.getFirstname(), p.getFirstname() );
        assertEquals( charlieClone.getLastname(), p.getLastname() );
        assertEquals( charlie.getBirthdate(), p.getBirthdate() );
        assertEquals( charlie.getFirstBaseBallGame(), p.getFirstBaseBallGame() );
        assertEquals( charlie.getWork(), p.getWork() );
        assertEquals( charlie.getWork().getZipcode(), p.getWork().getZipcode() );
        assertEquals( charlie.getHome(), p.getHome() );
        assertEquals( charlie.getHobbies().size(), p.getHobbies().size() );
        assertEquals( 1, p.getPhones().size() );
        assertEquals( 2, charlie.getPhones().size() );
        assertSame( fakePhone, p.getPhones().get(0) );
    }
View Full Code Here

        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        Person hank = new Person("Hank", "Paulsen", cal.getTime(), null, null);

        String json = new JSONSerializer().serialize(hank);
        Person deHank = new JSONDeserializer<Person>().deserialize(json, Person.class);

        assertEquals( hank.getFirstname(), deHank.getFirstname() );
        assertEquals( hank.getLastname(), deHank.getLastname() );
        assertEquals( hank.getBirthdate(), deHank.getBirthdate() );
    }
View Full Code Here

        ObjectBinder binder = new ObjectBinder();
        Object boundObject = binder.bind( map );

        assertEquals("Assert that we received a person class back.", Person.class, boundObject.getClass() );
        Person p = (Person)boundObject;
        assertEquals( "Charlie", p.getFirstname() );
        assertEquals( "Hubbard", p.getLastname() );
    }
View Full Code Here

        Map map = new HashMap();
        map.put("class", Person.class.getName() );
        map.put("birthdate", targetDate.getTime() );

        ObjectBinder binder = new ObjectBinder();
        Person person = (Person)binder.bind( map );

        assertEquals( targetDate, person.getBirthdate() );
    }
View Full Code Here

        Map map = new HashMap();
        map.put("class", Person.class.getName() );
        map.put("birthdate", targetDate.toString() );

        ObjectBinder binder = new ObjectBinder();
        Person person = (Person)binder.bind( map );

        assertEquals( targetDate, person.getBirthdate() );
    }
View Full Code Here

        Map map = new HashMap();
        map.put("class", Person.class.getName() );
        map.put("birthdate", (double)targetDate.getTime() );

        ObjectBinder binder = new ObjectBinder();
        Person person = (Person)binder.bind( map );

        assertEquals( targetDate, person.getBirthdate() );
    }
View Full Code Here

        map.put("work", work );

        map.put("phones", createPhoneMap(phones) );

        ObjectBinder binder = new ObjectBinder().use(Path.parse("phones.values"), new ClassLocatorObjectFactory( new StaticClassLocator(Phone.class) ) );
        Person person = (Person)binder.bind( map );

        assertTrue( "Make sure our array has stuff in it.", !person.getPhones().isEmpty() );
        assertEquals( 3, person.getPhones().size() );
        for( int i = 0; i < phones.size(); i++ ) {
            validatePhone( phones.get(i), (Phone)person.getPhones().get(i));
        }

        assertEquals( "Make sure our array has stuff in it.", 3, person.getPhones().size() );
    }
View Full Code Here

        map.put("lastname", "Hubbard");
        map.put("home", home );
        map.put("work", work );

        ObjectBinder binder = new ObjectBinder();
        Person person = (Person)binder.bind( map );

        assertEquals( home.get("street"), person.getHome().getStreet() );
        assertEquals( home.get("city"), person.getHome().getCity() );
        assertEquals( home.get("state"), person.getHome().getState() );
        assertEquals( zipcode.get("zipcode"), person.getHome().getZipcode().getZipcode() );
    }
View Full Code Here

TOP

Related Classes of flexjson.mock.Person

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.