• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JsonbBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



JsonbBuilder类属于javax.json.bind包,在下文中一共展示了JsonbBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: givenJavaTypes_shouldSerialise

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenJavaTypes_shouldSerialise() throws MalformedURLException, URISyntaxException {

    /*
        {
          "atomicInteger": 10,
          "bigDecimal": 10,
          "bigInteger": 10,
          "longAdder": 0,
          "optionalDouble": 10,
          "optionalInt": 10,
          "optionalLong": 10,
          "stringOptional": "Hello World",
          "uri": "http://www.readlearncode.com",
          "url": "http://www.readlearncode.com"
        }
     */

    String expectedJson = "{\"atomicInteger\":10,\"bigDecimal\":10,\"bigInteger\":10,\"longAdder\":0,\"optionalDouble\":10.0,\"optionalInt\":10,\"optionalLong\":10,\"stringOptional\":\"Hello World\",\"uri\":\"http://www.readlearncode.com\",\"url\":\"http://www.readlearncode.com\"}";
    String actualJson = JsonbBuilder.create().toJson(new JavaTypes());
    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:JSON-framework-comparison,代码行数:23,代码来源:JavaTypesTest.java


示例2: givenDateTypes_shouldSerialize

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenDateTypes_shouldSerialize() throws ParseException {

    /*
        {
          "date": "2017-12-25T00:00:00Z[UTC]",
          "dayOfWeek": "MONDAY",
          "localDate": "2017-12-25",
          "localDateTime": "2017-12-25T00:00:00",
          "offset": "+01:00",
          "offsetDateTime": "2017-12-25T00:00:00+01:00",
          "sixThirty": "23:00:00",
          "zoneId": "Europe/London",
          "zonedDateTime": "2017-12-25T00:00:00Z[Europe/London]"
        }
     */

    String expectedJson = "{\"date\":\"2017-12-25T00:00:00Z[UTC]\",\"dayOfWeek\":\"MONDAY\",\"localDate\":\"2017-12-25\",\"localDateTime\":\"2017-12-25T00:00:00\",\"offset\":\"+01:00\",\"offsetDateTime\":\"2017-12-25T00:00:00+01:00\",\"sixThirty\":\"23:00:00\",\"zoneId\":\"Europe/London\",\"zonedDateTime\":\"2017-12-25T00:00:00Z[Europe/London]\"}";
    String actualJson = JsonbBuilder.create().toJson(new AllDateTypes());
    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:JSON-framework-comparison,代码行数:22,代码来源:AllDateTypesTest.java


示例3: givenJsonProcessing_shouldSerialise

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenJsonProcessing_shouldSerialise(){

    /*
        {
          "jsonArray": [
            "Cat",
            "Dog"
          ],
          "jsonNumber": 100,
          "jsonObject": {
            "firstName": "Alex",
            "lastName": "Theedom"
          },
          "jsonString": "Flat",
          "jsonValue": "House"
        }
     */

    String expectedJson = "{\"jsonArray\":[\"Cat\",\"Dog\"],\"jsonNumber\":100,\"jsonObject\":{\"firstName\":\"Alex\",\"lastName\":\"Theedom\"},\"jsonString\":\"Flat\",\"jsonValue\":\"House\"}";
    String actualJson = JsonbBuilder.create().toJson(new JsonProcessingTypes());
    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:JSON-framework-comparison,代码行数:24,代码来源:JsonProcessingTypesTest.java


示例4: writeTo

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Override
public void writeTo(User t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    t.setPassword(null);
    JsonbConfig config = new JsonbConfig().withNullValues(false);
    JsonbBuilder.create(config)
        .toJson(t, entityStream);
}
 
开发者ID:hantsy,项目名称:javaee8-jaxrs-sample,代码行数:8,代码来源:UserMessageBodyWiter.java


示例5: givenFieldVisibility_shouldSerialise

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenFieldVisibility_shouldSerialise() {
    /*
        {
          "defaultStringWithSetterGetter": "",
          "finalPrivateStringWithSetterGetter": "",
          "finalPublicString": "",
          "finalPublicStringWithSetterGetter": "",
          "privateStringWithSetterGetter": "",
          "protectedStringWithSetterGetter": "",
          "publicString": "",
          "publicStringWithSetterGetter": "",
          "virtualField": ""
        }
     */

    String expectedJson = "{\"defaultStringWithSetterGetter\":\"\",\"finalPrivateStringWithSetterGetter\":\"\",\"finalPublicString\":\"\",\"finalPublicStringWithSetterGetter\":\"\",\"privateStringWithSetterGetter\":\"\",\"protectedStringWithSetterGetter\":\"\",\"publicString\":\"\",\"publicStringWithSetterGetter\":\"\",\"virtualField\":\"\"}";
    String actualJson = JsonbBuilder.create().toJson(new FieldsVisibility());
    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:JSON-framework-comparison,代码行数:21,代码来源:FieldsVisibilityTest.java


示例6: test_using_jsonbConfig

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void test_using_jsonbConfig() {
    String expectedJson = "\n" +
            "{\n" +
            "    \"string\": null,\n" +
            "    \"shortWrapper\": null,\n" +
            "    \"shortPrimitive\": null,\n" +
            "    \"longWrapper\": null,\n" +
            "    \"longPrimitive\": null,\n" +
            "    \"intWrapper\": null,\n" +
            "    \"intPrimitive\": null,\n" +
            "    \"floatWrapper\": null,\n" +
            "    \"floatPrimitive\": null,\n" +
            "    \"doubleWrapper\": null,\n" +
            "    \"doublePrimitive\": null,\n" +
            "    \"charWrapper\": null,\n" +
            "    \"charPrimitive\": null,\n" +
            "    \"byteWrapper\": null,\n" +
            "    \"bytePrimitive\": null,\n" +
            "    \"booleanWrapper\": null,\n" +
            "    \"aBoolean\": null\n" +
            "}";
    String actualJson = JsonbBuilder.create(RuntimeSampler.jsonbConfig()).toJson(new AllBasicTypes());
    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:JSON-framework-comparison,代码行数:26,代码来源:RuntimeSamplerTest.java


示例7: getIt

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
/**
 * Method handling HTTP GET requests. The returned object will be sent
 * to the client as "text/plain" media type.
 *
 * @return String that will be returned as a text/plain response.
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getIt() {
    JsonbConfig config = new JsonbConfig();

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

    CEntity entity = new EntityImpl("urn:c3im:Vehicle:4567", "Vehicle");
    CProperty propertySt = new CPropertyImpl("speed", 40);

    entity.addProperty(propertySt);

    return jsonb.toJson(entity);
}
 
开发者ID:Fiware,项目名称:NGSI-LD_Wrapper,代码行数:22,代码来源:MyResourceJson2.java


示例8: getDecision

import javax.json.bind.JsonbBuilder; //导入依赖的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


示例9: serialiseMagazine

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
public String serialiseMagazine() throws MalformedURLException {
    Magazine magazine = new Magazine();
    magazine.setId("ABCD-1234");
    magazine.setTitle("Fun with Java");
    magazine.setAuthor(new Author("Alex", "Theedom"));
    magazine.setPrice(45.00f);
    magazine.setPages(300);
    magazine.setInPrint(true);
    magazine.setBinding(Binding.SOFT_BACK);
    magazine.setLanguages(Arrays.asList("French", "English", "Spanish", null));
    magazine.setWebsite(new URL("https://www.readlearncode.com"));
    magazine.setInternalAuditCode("IN-675X-NF09"); // Only has setter method
    magazine.setPublished(LocalDate.parse("01/01/2018", DateTimeFormatter.ofPattern("MM/dd/yyyy")));
    magazine.setAlternativeTitle(null);
    return JsonbBuilder.create().toJson(magazine);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:17,代码来源:ComprehensiveExample.java


示例10: givenSerialize_shouldSerialiseMagazine

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenSerialize_shouldSerialiseMagazine() {

    Magazine magazine = new Magazine();
    magazine.setId("1234-QWERT");
    magazine.setTitle("Fun with Java");
    magazine.setAuthor(new Author("Alex","Theedom"));

    String expectedJson = "{\"name\":{\"firstName\":\"Alex\",\"lastName\":\"Theedom\"}}";

    JsonbConfig config = new JsonbConfig().withSerializers(new MagazineSerializer());
    Jsonb jsonb = JsonbBuilder.newBuilder().withConfig(config).build();
    String actualJson = jsonb.toJson(magazine);
    assertThat(actualJson).isEqualTo(expectedJson);

}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:17,代码来源:MagazineSerializerTest.java


示例11: givenIDENTITYStrategy_shouldNotChangeAnyPropertyName

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenIDENTITYStrategy_shouldNotChangeAnyPropertyName() {
    /*
        {
          "alternativetitle": "Fun with JSON-B",
          "authorName": {
            "firstName": "Alex",
            "lastName": "Theedom"
          },
          "title": "Fun with JSON binding"
        }
     */

    String expectedJson = "{\"alternativetitle\":\"Fun with JSON-B\",\"authorName\":{\"firstName\":\"Alex\",\"lastName\":\"Theedom\"},\"title\":\"Fun with JSON binding\"}";
    JsonbConfig jsonbConfig = new JsonbConfig()
            .withPropertyNamingStrategy(PropertyNamingStrategy.IDENTITY);

    String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);

    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:22,代码来源:CustomisePropertyNamingStrategyTest.java


示例12: givenLOWER_CASE_WITH_DASHESStrategy_shouldDelimitPropertyNameWithDashes

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenLOWER_CASE_WITH_DASHESStrategy_shouldDelimitPropertyNameWithDashes() {
    /*
        {
          "alternativetitle": "Fun with JSON-B",
          "author-name": {
            "first-name": "Alex",
            "last-name": "Theedom"
          },
          "title": "Fun with JSON binding"
        }
     */

    String expectedJson = "{\"alternativetitle\":\"Fun with JSON-B\",\"author-name\":{\"first-name\":\"Alex\",\"last-name\":\"Theedom\"},\"title\":\"Fun with JSON binding\"}";
    JsonbConfig jsonbConfig = new JsonbConfig()
            .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES);

    String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);

    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:22,代码来源:CustomisePropertyNamingStrategyTest.java


示例13: givenLOWER_CASE_WITH_DASHESStrategy_shouldDeserialiseCorrectly

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenLOWER_CASE_WITH_DASHESStrategy_shouldDeserialiseCorrectly() {
    /*
        {
          "alternativetitle": "Fun with JSON-B",
          "author-name": {
            "first-name": "Alex",
            "last-name": "Theedom"
          },
          "title": "Fun with JSON binding"
        }
     */

    String expectedJson = "{\"alternativetitle\":\"Fun with JSON-B\",\"author-name\":{\"first-name\":\"Alex\",\"last-name\":\"Theedom\"},\"title\":\"Fun with JSON binding\"}";
    JsonbConfig jsonbConfig = new JsonbConfig()
            .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES);

    Magazine magazine = JsonbBuilder.create(jsonbConfig).fromJson(expectedJson, Magazine.class);

    assertThat(magazine.getAlternativetitle()).isEqualTo("Fun with JSON-B");
    assertThat(magazine.getAuthorName().getFirstName()).isEqualTo("Alex");
    assertThat(magazine.getAuthorName().getLastName()).isEqualTo("Theedom");
    assertThat(magazine.getTitle()).isEqualTo("Fun with JSON binding");
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:25,代码来源:CustomisePropertyNamingStrategyTest.java


示例14: givenLOWER_CASE_WITH_UNDERSCORESStrategy_shouldDelimitLowercasePropertyNameWithUnderscore

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenLOWER_CASE_WITH_UNDERSCORESStrategy_shouldDelimitLowercasePropertyNameWithUnderscore() {
    /*
        {
          "alternativetitle": "Fun with JSON-B",
          "author_name": {
            "first_name": "Alex",
            "last_name": "Theedom"
          },
          "title": "Fun with JSON binding"
        }
     */

    String expectedJson = "{\"alternativetitle\":\"Fun with JSON-B\",\"author_name\":{\"first_name\":\"Alex\",\"last_name\":\"Theedom\"},\"title\":\"Fun with JSON binding\"}";
    JsonbConfig jsonbConfig = new JsonbConfig()
            .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_UNDERSCORES);

    String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);

    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:22,代码来源:CustomisePropertyNamingStrategyTest.java


示例15: givenUPPER_CAMEL_CASEStrategy_shouldDelimitLowercasePropertyNameWithUnderscore

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenUPPER_CAMEL_CASEStrategy_shouldDelimitLowercasePropertyNameWithUnderscore() {
    /*
        {
          "Alternativetitle": "Fun with JSON-B",
          "AuthorName": {
            "FirstName": "Alex",
            "LastName": "Theedom"
          },
          "Title": "Fun with JSON binding"
        }
     */

    String expectedJson = "{\"Alternativetitle\":\"Fun with JSON-B\",\"AuthorName\":{\"FirstName\":\"Alex\",\"LastName\":\"Theedom\"},\"Title\":\"Fun with JSON binding\"}";
    JsonbConfig jsonbConfig = new JsonbConfig()
            .withPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);

    String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);

    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:22,代码来源:CustomisePropertyNamingStrategyTest.java


示例16: givenUPPER_CAMEL_CASE_WITH_SPACESStrategy_shouldDelimitLowercasePropertyNameWithUnderscore

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenUPPER_CAMEL_CASE_WITH_SPACESStrategy_shouldDelimitLowercasePropertyNameWithUnderscore() {
    /*
        {
          "Alternativetitle": "Fun with JSON-B",
          "Author Name": {
            "First Name": "Alex",
            "Last Name": "Theedom"
          },
          "Title": "Fun with JSON binding"
        }
     */

    String expectedJson = "{\"Alternativetitle\":\"Fun with JSON-B\",\"Author Name\":{\"First Name\":\"Alex\",\"Last Name\":\"Theedom\"},\"Title\":\"Fun with JSON binding\"}";
    JsonbConfig jsonbConfig = new JsonbConfig()
            .withPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE_WITH_SPACES);

    String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);

    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:22,代码来源:CustomisePropertyNamingStrategyTest.java


示例17: givenCASE_INSENSITIVEStrategy_shouldDelimitLowercasePropertyNameWithUnderscore

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenCASE_INSENSITIVEStrategy_shouldDelimitLowercasePropertyNameWithUnderscore() {
    /*
        {
          "alternativetitle": "Fun with JSON-B",
          "authorName": {
            "firstName": "Alex",
            "lastName": "Theedom"
          },
          "title": "Fun with JSON binding"
        }
     */

    String expectedJson = "{\"alternativetitle\":\"Fun with JSON-B\",\"authorName\":{\"firstName\":\"Alex\",\"lastName\":\"Theedom\"},\"title\":\"Fun with JSON binding\"}";
    JsonbConfig jsonbConfig = new JsonbConfig()
            .withPropertyNamingStrategy(PropertyNamingStrategy.CASE_INSENSITIVE);

    String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);

    assertThat(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:22,代码来源:CustomisePropertyNamingStrategyTest.java


示例18: givenJsonbPropertyOrderSet_shouldOrderProperties

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenJsonbPropertyOrderSet_shouldOrderProperties() {
    /*
        {
          "id": "ABC-123-XYZ",
          "title": "Fun with JSON-B",
          "author": "Alex Theedom"
        }
     */

    String expectedJson = "{\"id\":\"ABC-123-XYZ\",\"title\":\"Fun with JSON-B\",\"author\":\"Alex Theedom\"}";
    Book book = new Book("ABC-123-XYZ", "Fun with JSON-B", "Alex Theedom");

    String actualJson = JsonbBuilder.create().toJson(book);

    assertThat(expectedJson).isEqualTo(actualJson);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:18,代码来源:CustomisePropertyOrderStrategyTest.java


示例19: givenBookObject_shouldSerialise

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void givenBookObject_shouldSerialise() {
    String expectedJson = "{\"title\":\"Fun with Java\"}";

    Book book = new Book();
    book.title = "Fun with Java";

    String actualJson = JsonbBuilder.create().toJson(book);

    assertThat(actualJson).isEqualTo(expectedJson);

    /*
        {
          "title": "Fun with Java"
        }
     */
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:18,代码来源:SimplestExampleTest.java


示例20: deserializeBook

import javax.json.bind.JsonbBuilder; //导入依赖的package包/类
@Test
public void deserializeBook() {

    Book expectedBook = new Book();
    expectedBook.setTitle("Fun with Java");
    expectedBook.setFirstname("John");
    expectedBook.setMiddleInitial('J');
    expectedBook.setLastname("Smith");
    expectedBook.setPrice(59.99f);
    expectedBook.setInPrint(true);
    expectedBook.setPages(200);
    expectedBook.setVersion((byte) 5);
    expectedBook.setCount(new AtomicInteger(4));

    String json = "{\"count\":4,\"firstname\":\"John\",\"inPrint\":true,\"lastname\":\"Smith\",\"middleInitial\":\"J\",\"pages\":200,\"price\":59.99,\"title\":\"Fun with Java\",\"version\":5}";

    assertThatThrownBy(() -> JsonbBuilder.create().fromJson(json, Book.class))
            .isInstanceOf(IllegalArgumentException.class)
            .hasMessageContaining("argument type mismatch");

}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:22,代码来源:BasicTypeExampleTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JksOptions类代码示例发布时间:2022-05-21
下一篇:
Java RequestLogHandler类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap