当前位置: 首页>>代码示例>>Java>>正文


Java Jsonb.fromJson方法代码示例

本文整理汇总了Java中javax.json.bind.Jsonb.fromJson方法的典型用法代码示例。如果您正苦于以下问题:Java Jsonb.fromJson方法的具体用法?Java Jsonb.fromJson怎么用?Java Jsonb.fromJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.json.bind.Jsonb的用法示例。


在下文中一共展示了Jsonb.fromJson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
/**
 * accept = application/json
 * @param <T>
 * @param url
 * @param entity
 * @return ClientResponse
 * @throws java.io.IOException
 */
public static <T> T get(String url,Class<?> entity) throws IOException{
      OkHttpClient client = new OkHttpClient();
      Request request = new Request.Builder()
        .url(url)
        .header("Accept", "application/json")
        .get()
        .build();
      
      Response response = client.newCall(request).execute();
      client.dispatcher().executorService().shutdown();
      if(response.code() == 200){
          Jsonb jsonb = JsonbBuilder.create();
            return (T) jsonb.fromJson(response.body().string(), entity);
      }
      return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:25,代码来源:DiavgeiaHttpUtils.java

示例2: getOrganization

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
/**
 * accept = application/json
 * @param url
 * @return OrganizationDao
 * @throws java.io.IOException
 */
public static OrganizationDao getOrganization(String url) throws IOException {
      OkHttpClient client = new OkHttpClient();
      Request request = new Request.Builder()
        .url(url)
         .header("Accept", "application/json")
        .get()
        .build();
      
      Response response = client.newCall(request).execute();
      client.dispatcher().executorService().shutdown();
      if(response.code() == 200){
          Jsonb jsonb = JsonbBuilder.create();
            return jsonb.fromJson(response.body().string(), OrganizationDao.class);
      }
      return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:23,代码来源:DiavgeiaHttpUtils.java

示例3: getDecisionTypeDetailsDao

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
public static DecisionTypeDetailsDao getDecisionTypeDetailsDao(String url) throws IOException {
      OkHttpClient client = new OkHttpClient();
      Request request = new Request.Builder()
        .url(url)
        .header("Accept", "application/json")
        .get()
        .build();
      
      Response response = client.newCall(request).execute();
      client.dispatcher().executorService().shutdown();
      if(response.code() == 200){
          Jsonb jsonb = JsonbBuilder.create();
            return jsonb.fromJson(response.body().string(), DecisionTypeDetailsDao.class);
      }
      return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:17,代码来源:DiavgeiaHttpUtils.java

示例4: getDictionaryItemsDao

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
public static DictionaryItemsDao getDictionaryItemsDao(String url) throws IOException {
      OkHttpClient client = new OkHttpClient();
      Request request = new Request.Builder()
        .url(url)
        .header("Accept", "application/json")
        .get()
        .build();
      
      Response response = client.newCall(request).execute();
      client.dispatcher().executorService().shutdown();
      if(response.code() == 200){
          Jsonb jsonb = JsonbBuilder.create();
            return jsonb.fromJson(response.body().string(), DictionaryItemsDao.class);
      }
      return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:17,代码来源:DiavgeiaHttpUtils.java

示例5: getSignersDao

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
public static SignersDao getSignersDao(String url) throws IOException{
      OkHttpClient client = new OkHttpClient();
      Request request = new Request.Builder()
        .url(url)
        .header("Accept", "application/json")
        .get()
        .build();
      
      Response response = client.newCall(request).execute();
      client.dispatcher().executorService().shutdown();
      if(response.code() == 200){
          Jsonb jsonb = JsonbBuilder.create();
            return jsonb.fromJson(response.body().string(), SignersDao.class);
      }
      return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:17,代码来源:DiavgeiaHttpUtils.java

示例6: getUnitsDao

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
public static UnitsDao getUnitsDao(String url) throws IOException {
      OkHttpClient client = new OkHttpClient();
      Request request = new Request.Builder()
        .url(url)
        .header("Accept", "application/json")
        .get()
        .build();
      
      Response response = client.newCall(request).execute();
      client.dispatcher().executorService().shutdown();
      if(response.code() == 200){
          Jsonb jsonb = JsonbBuilder.create();
            return jsonb.fromJson(response.body().string(), UnitsDao.class);
      }
      return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:17,代码来源:DiavgeiaHttpUtils.java

示例7: getDictionaryItems

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
public static DictionaryItemsDao getDictionaryItems(String url) throws IOException {
      OkHttpClient client = new OkHttpClient();
      Request request = new Request.Builder()
        .url(url)
        .header("Accept", "application/json")
        .get()
        .build();
      
      Response response = client.newCall(request).execute();
      client.dispatcher().executorService().shutdown();
      if(response.code() == 200){
          Jsonb jsonb = JsonbBuilder.create();
            return jsonb.fromJson(response.body().string(), DictionaryItemsDao.class);
      }
      return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:17,代码来源:DiavgeiaHttpUtils.java

示例8: getTypes

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
public static DecisionTypesDao getTypes(String url) throws IOException {
     OkHttpClient client = new OkHttpClient();
     Request request = new Request.Builder()
       .url(url)
       .header("Accept", "application/json")
       .get()
       .build();
     
     Response response = client.newCall(request).execute();
     client.dispatcher().executorService().shutdown();
     if(response.code() == 200){
         Jsonb jsonb = JsonbBuilder.create();
       return jsonb.fromJson(response.body().string(), DecisionTypesDao.class);
     }
     return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:17,代码来源:DiavgeiaHttpUtils.java

示例9: getDecision

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
public static DecisionDao getDecision(String url) throws IOException {
     OkHttpClient client = new OkHttpClient();
     Request request = new Request.Builder()
       .url(url)
       .header("Accept", "application/json")
       .get()
       .build();
     
     Response response = client.newCall(request).execute();
     client.dispatcher().executorService().shutdown();
     if(response.code() == 200){
         Jsonb jsonb = JsonbBuilder.create();
       return jsonb.fromJson(response.body().string(), DecisionDao.class);
     }
     return null;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:17,代码来源:DiavgeiaHttpUtils.java

示例10: testSerializerSerializationOfType

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
/**
 * Tests JSONB serialization of arbitrary type invoked from a Serializer.
 */
@Test
public void testSerializerSerializationOfType() {
    JsonbConfig config = new JsonbConfig().withSerializers(new CrateSerializer());
    Jsonb jsonb = JsonbBuilder.create(config);
    String expected = "{\"boxStr\":\"Box string\",\"crate\":{\"crateStr\":\"REPLACED crate str\",\"crateInner\":{\"crateInnerBigDec\":10,\"crate_inner_str\":\"Single inner\"},\"crateInnerList\":[{\"crateInnerBigDec\":10,\"crate_inner_str\":\"List inner 0\"},{\"crateInnerBigDec\":10,\"crate_inner_str\":\"List inner 1\"}],\"crateBigDec\":54321},\"secondBoxStr\":\"Second box string\"}";
    Box pojo = createPojo();

    assertEquals(expected, jsonb.toJson(pojo));

    Box result = jsonb.fromJson(expected, Box.class);
    assertEquals(new BigDecimal("54321"), result.crate.crateBigDec);
    //result.crate.crateStr is mapped to crate_str by jsonb property
    assertNull(result.crate.crateStr);
    assertEquals(pojo.crate.crateInner.crateInnerStr, result.crate.crateInner.crateInnerStr);
    assertEquals(pojo.crate.crateInner.crateInnerBigDec, result.crate.crateInner.crateInnerBigDec);
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:20,代码来源:SerializersTest.java

示例11: testMarshallOptionalIntArray

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
@Test
public void testMarshallOptionalIntArray() {
    final Jsonb jsonb = (new JsonBindingBuilder()).build();

    final OptionalInt[] array = {OptionalInt.of(1), OptionalInt.of(2), OptionalInt.empty()};
    assertEquals("[1,2,null]", jsonb.toJson(array));

    OptionalInt[] result = jsonb.fromJson("[1,2,null]", new TestTypeToken<OptionalInt[]>() {}.getType());

    assertTrue(result[0].isPresent());
    assertEquals(1, result[0].getAsInt());

    assertTrue(result[1].isPresent());
    assertEquals(2, result[1].getAsInt());

    assertEquals(OptionalInt.empty(), result[2]);
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:18,代码来源:OptionalTest.java

示例12: testContainerSerializer

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
@Test
public void testContainerSerializer() {
    Jsonb jsonb = JsonbBuilder.create();

    SimpleAnnotatedSerializedArrayContainer container = new SimpleAnnotatedSerializedArrayContainer();
    SimpleContainer instance1 = new SimpleContainer();
    instance1.setInstance("Test String 1");
    SimpleContainer instance2 = new SimpleContainer();
    instance2.setInstance("Test String 2");
    container.setArrayInstance(new SimpleContainer[] {instance1, instance2});

    container.setListInstance(new ArrayList<>());
    container.getListInstance().add(new SimpleContainer("Test List 1"));
    container.getListInstance().add(new SimpleContainer("Test List 2"));

    String jsonString = jsonb.toJson(container);
    Assert.assertEquals("{\"arrayInstance\":[{\"instance\":\"Test String 1\"},{\"instance\":\"Test String 2\"}],\"listInstance\":[{\"instance\":\"Test List 1\"},{\"instance\":\"Test List 2\"}]}", jsonString);

    SimpleAnnotatedSerializedArrayContainer unmarshalledObject = jsonb.fromJson("{\"arrayInstance\":[{\"instance\":\"Test String 1\"},{\"instance\":\"Test String 2\"}],\"listInstance\":[{\"instance\":\"Test List 1\"},{\"instance\":\"Test List 2\"}]}", SimpleAnnotatedSerializedArrayContainer.class);

    Assert.assertEquals("Test String 1", unmarshalledObject.getArrayInstance()[0].getInstance());
    Assert.assertEquals("Test String 2", unmarshalledObject.getArrayInstance()[1].getInstance());

    Assert.assertEquals("Test List 1", unmarshalledObject.getListInstance().get(0).getInstance());
    Assert.assertEquals("Test List 2", unmarshalledObject.getListInstance().get(1).getInstance());
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:27,代码来源:SerializersTest.java

示例13: adapt

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
@Test
public void adapt() {
    final Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withAdapters(new BarAdapter()));
    final Foo foo = new Foo();
    foo.bar = new Bar();
    foo.bar.value = 1;
    foo.dummy = new Dummy();
    foo.dummy.value = 2L;

    final String toString = jsonb.toJson(foo);
    assertEquals("{\"bar\":\"1\",\"dummy\":\"2\"}", toString);

    final Foo read = jsonb.fromJson(toString, Foo.class);
    assertEquals(foo.bar.value, read.bar.value);
    assertEquals(foo.dummy.value, read.dummy.value);
}
 
开发者ID:apache,项目名称:johnzon,代码行数:17,代码来源:AdapterTest.java

示例14: addEntity

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addEntity(String ent) {
    JsonbConfig config = new JsonbConfig();

    config.withAdapters(new EntityAdapter());
    Jsonb jsonb = JsonbBuilder.create(config);

    JsonObject obj = null;

    try {
        CEntity entity = jsonb.fromJson(ent, EntityImpl.class);

        obj = Ngsi2NGSILD.toNgsi(entity);
    }
    catch(Exception ex) {
        if(ex.getCause().getMessage().equals("400")) {
           return Response.status(400).build();
        }
    }

    NgsiClient client = new NgsiClient(Configuration.ORION_BROKER);
    Response res = client.createEntity(obj);

    if(res.getStatus() == 201) {
        res = Response.status(201).location(URI.create(
                "entities/" + obj.getString("id"))).build();
    }

    return res;
}
 
开发者ID:Fiware,项目名称:NGSI-LD_Wrapper,代码行数:32,代码来源:EntityResource.java

示例15: deserializeBook

import javax.json.bind.Jsonb; //导入方法依赖的package包/类
public Book deserializeBook() {
    Book book = new Book("SHDUJ-4532", "Fun with Java", "Alex Theedom");
    Jsonb jsonb = JsonbBuilder.create();
    String json = jsonb.toJson(book);
    book = jsonb.fromJson(json, Book.class);
    return book;
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:8,代码来源:MinimalExample.java


注:本文中的javax.json.bind.Jsonb.fromJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。