Package jodd.json.mock.superhero

Examples of jodd.json.mock.superhero.Hero


  @Test
  public void testNoHintsButClassesForCollection() {
    JoddJson.classMetadataName = "class";

    Hero superman = creator.createSuperman();
    String json = new JsonSerializer()
        .exclude("*.class")
        .include("powers.class")
        .serialize(superman);
    Hero jsonSuperMan = new JsonParser().parse(json, Hero.class);
    assertHeroHasSuperPowers(jsonSuperMan);
  }
View Full Code Here


  @Test
  public void testNoClassHintsForCollections() {
    JoddJson.classMetadataName = "class";

    Hero superman = creator.createSuperman();
    String json = new JsonSerializer()
        .include("powers")        // redudant
        .include("powers.class")
        .use("powers.class", new SimpleClassnameTransformer())
        .exclude("*.class")
        .serialize(superman);

    int count = StringUtil.count(json, "***");
    assertEquals(4, count);

    json = StringUtil.remove(json, "***");

    Hero jsonSuperMan = new JsonParser()
        .map("lair", SecretLair.class)
        .map("secretIdentity", SecretIdentity.class)
        .parse(json, Hero.class);

    assertHeroHasSuperPowers(jsonSuperMan);
View Full Code Here

        new Address("123 Finland Dr", "Cubicleville", "Hell", new Zipcode("66666")),
        new Address("123 Finland Dr", "Cubicleville", "Hell", new Zipcode("66666")), "Initech");
  }

  public Hero createSuperman() {
    return new Hero("Super Man",
        new SecretIdentity("Clark Kent"),
        new SecretLair("Fortress of Solitude"),
        new XRayVision(0.8f),
        new HeatVision(0.7f),
        new Flight(1000.0f),
View Full Code Here

    assertEquals(dilbert.getCompany(), ((Employee) jsonDilbert).getCompany());
  }

  @Test
  public void testDeserializeInterfaces() {
    Hero superman = creator.createSuperman();
    String json = new JsonSerializer().include("powers").setClassMetadataName("class").serialize(superman);
    Hero jsonSuperMan = new JsonParser().setClassMetadataName("class").parse(json, Hero.class);

    assertNotNull(jsonSuperMan);
    assertEquals(4, jsonSuperMan.getPowers().size());
    assertHeroHasSuperPowers(jsonSuperMan);

    JoddJson.classMetadataName = null;
  }
View Full Code Here

  @Test
  public void testNoClassHints() {
    JoddJson.classMetadataName = null;

    Hero superman = creator.createSuperman();
    String json = new JsonSerializer().exclude("*.class").serialize(superman);

    Hero jsonSuperMan = new JsonParser()
        .map(Hero.class)
        .map("lair", SecretLair.class)
        .map("secretIdentity", SecretIdentity.class)
        .parse(json);

    assertNotNull(jsonSuperMan);
    assertEquals("Super Man", jsonSuperMan.getName());
    assertNotNull(jsonSuperMan.getIdentity());
    assertEquals("Clark Kent", jsonSuperMan.getIdentity().getName());
    assertNotNull(jsonSuperMan.getLair());
    assertEquals("Fortress of Solitude", jsonSuperMan.getLair().getName());
  }
View Full Code Here

TOP

Related Classes of jodd.json.mock.superhero.Hero

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.