Examples of JsonMapper


Examples of com.dsindigo.mundojoven.uno.service.JsonMapper

    try {
      LOG.info( "Configurando Spring" );
      AbstractApplicationContext context = new ClassPathXmlApplicationContext( new String[]{ "spring-configuration.xml" } );
      context.registerShutdownHook();

      JsonMapper jsonMapper = context.getBean( "jsonMapper", JsonMapper.class );
      String json = jsonMapper.vuelo2Json( mockVuelo() );
      Vuelo vuelo = jsonMapper.json2Vuelo( json );
      String reJson = jsonMapper.vuelo2Json( vuelo );

      if( json.equals( reJson ) ) {
        LOG.info( "Todo chido!" );
      } else {
        LOG.error( "Oooops!" );
View Full Code Here

Examples of com.mossle.core.mapper.JsonMapper

        try {
            String content = httpHandler.readText(url, parameterMap);
            logger.info(content);

            JsonMapper jsonMapper = new JsonMapper();
            Map map = jsonMapper.fromJson(content, Map.class);
            logger.debug("{}", map);

            long userId = ((Number) map.get("userId")).longValue();

            List<String> authorities = (List<String>) map.get("authorities");
View Full Code Here

Examples of com.mossle.core.mapper.JsonMapper

        try {
            String content = httpHandler.readText(url, parameterMap);
            logger.info(content);

            JsonMapper jsonMapper = new JsonMapper();
            List<Map> list = jsonMapper.fromJson(content, List.class);

            Map<String, String> resourceMap = new LinkedHashMap<String, String>();

            for (Map map : list) {
                String access = (String) map.get("access");
View Full Code Here

Examples of com.restfb.JsonMapper

    // Make the API call
    JsonObject results = facebookClient.fetchObjects(ids, JsonObject.class);

    // Pull out JSON data by key and map each type by hand.
    JsonMapper jsonMapper = new DefaultJsonMapper();
    User user = jsonMapper.toJavaObject(results.getString("btaylor"), User.class);
    Url url = jsonMapper.toJavaObject(results.getString("http://www.imdb.com/title/tt0117500/"), Url.class);

    out.println("User is " + user);
    out.println("URL is " + url);
  }
View Full Code Here

Examples of com.restfb.JsonMapper

    // Make the API call
    JsonObject results = facebookClient.fetchObjects(ids, JsonObject.class);

    // Pull out JSON data by key and map each type by hand.
    JsonMapper jsonMapper = new DefaultJsonMapper();
    User user = jsonMapper.toJavaObject(results.getString("btaylor"), User.class);
    Url url = jsonMapper.toJavaObject(results.getString("http://www.imdb.com/title/tt0117500/"), Url.class);

    out.println("User is " + user);
    out.println("URL is " + url);
  }
View Full Code Here

Examples of org.springside.modules.mapper.JsonMapper

  @Test
  public void threeTypeInclusion() {
    TestBean bean = new TestBean("A");

    // 打印全部属性
    JsonMapper normalMapper = new JsonMapper();
    assertThat(normalMapper.toJson(bean)).isEqualTo(
        "{\"name\":\"A\",\"defaultValue\":\"hello\",\"nullValue\":null}");

    // 不打印nullValue属性
    JsonMapper nonEmptyMapper = JsonMapper.nonEmptyMapper();
    assertThat(nonEmptyMapper.toJson(bean)).isEqualTo("{\"name\":\"A\",\"defaultValue\":\"hello\"}");

    // 不打印默认值未改变的nullValue与defaultValue属性
    JsonMapper nonDefaultMaper = JsonMapper.nonDefaultMapper();
    assertThat(nonDefaultMaper.toJson(bean)).isEqualTo("{\"name\":\"A\"}");
  }
View Full Code Here

Examples of org.springside.modules.mapper.JsonMapper

  /*
   * 测试直接使用Jaxb的annotaion
   */
  @Test
  public void jaxbAnnoation() {
    JsonMapper newMapper = new JsonMapper();
    newMapper.enableJaxbAnnotation();
    TestBean3 testBean = new TestBean3(1, "foo", 18);
    // 结果name属性输出在前,且被改名为productName,且age属性被ignore
    assertThat(newMapper.toJson(testBean)).isEqualTo("{\"productName\":\"foo\",\"id\":1}");
  }
View Full Code Here

Examples of org.springside.modules.mapper.JsonMapper

    assertThat(mapper.fromJson("\"One\"", TestEnum.class)).isEqualTo(TestEnum.One);
    assertThat(mapper.fromJson("0", TestEnum.class)).isEqualTo(TestEnum.One);

    // 使用enum.toString(), 注意配置必須在所有讀寫動作之前調用.
    // 建议toString()使用index数字属性,比enum.name()节约了空间,比enum.order()则不会有顺序随时改变不确定的问题。
    JsonMapper newMapper = new JsonMapper();
    newMapper.enableEnumUseToString();
    assertThat(newMapper.toJson(TestEnum.One)).isEqualTo("\"1\"");
    assertThat(newMapper.fromJson("\"1\"", TestEnum.class)).isEqualTo(TestEnum.One);
  }
View Full Code Here

Examples of org.springside.modules.mapper.JsonMapper

   * 测试自定义转换器,整体感觉稍显复杂。这里是将Money和Long互转.
   */
  @Test
  public void customConverter() {

    JsonMapper newMapper = JsonMapper.nonEmptyMapper();

    SimpleModule moneyModule = new SimpleModule("MoneyModule");
    moneyModule.addSerializer(new MoneySerializer());
    moneyModule.addDeserializer(Money.class, new MoneyDeserializer());
    newMapper.getMapper().registerModule(moneyModule);

    // tojson
    User user = new User();
    user.setName("foo");
    user.setSalary(new Money(1.2));

    String jsonString = newMapper.toJson(user);

    assertThat(jsonString).isEqualTo("{\"name\":\"foo\",\"salary\":\"1.2\"}");

    // from
    User resultUser = newMapper.fromJson(jsonString, User.class);
    assertThat(resultUser.getSalary().value).isEqualTo(1.2);

  }
View Full Code Here

Examples of org.springside.modules.mapper.JsonMapper

  @Test
  public void customPropertyNaming() throws JsonMappingException {

    TestBean bean = new TestBean("foo");
    bean.setDefaultValue("bar");
    JsonMapper newMapper = JsonMapper.nonEmptyMapper();
    newMapper.getMapper().setPropertyNamingStrategy(new LowerCaseNaming());
    assertThat(newMapper.toJson(bean)).isEqualTo("{\"name\":\"foo\",\"defaultvalue\":\"bar\"}");
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.