本文整理汇总了Java中javax.json.bind.config.PropertyOrderStrategy类的典型用法代码示例。如果您正苦于以下问题:Java PropertyOrderStrategy类的具体用法?Java PropertyOrderStrategy怎么用?Java PropertyOrderStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyOrderStrategy类属于javax.json.bind.config包,在下文中一共展示了PropertyOrderStrategy类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initOrderStrategy
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
private PropOrderStrategy initOrderStrategy() {
final Optional<Object> property = jsonbConfig.getProperty(JsonbConfig.PROPERTY_ORDER_STRATEGY);
if (property.isPresent()) {
final Object strategy = property.get();
if (!(strategy instanceof String)) {
throw new JsonbException(Messages.getMessage(MessageKeys.PROPERTY_ORDER, strategy));
}
switch ((String) strategy) {
case PropertyOrderStrategy.LEXICOGRAPHICAL:
return new LexicographicalOrderStrategy();
case PropertyOrderStrategy.REVERSE:
return new ReverseOrderStrategy();
case PropertyOrderStrategy.ANY:
return new AnyOrderStrategy();
default:
throw new JsonbException(Messages.getMessage(MessageKeys.PROPERTY_ORDER, strategy));
}
}
//default by spec
return new LexicographicalOrderStrategy();
}
开发者ID:eclipse,项目名称:yasson,代码行数:22,代码来源:JsonbConfigProperties.java
示例2: jsonbConfig
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
public static JsonbConfig jsonbConfig() {
return new JsonbConfig()
// Property visibility
.withNullValues(true)
.withPropertyVisibilityStrategy(new PropertyVisibilityStrategy() {
@Override
public boolean isVisible(Field field) {
return false;
}
@Override
public boolean isVisible(Method method) {
return false;
}
})
// Property naming and order
.withPropertyNamingStrategy(PropertyNamingStrategy.CASE_INSENSITIVE)
.withPropertyOrderStrategy(PropertyOrderStrategy.REVERSE)
// Customised de/serializers
.withAdapters(new ClassAdapter())
.withDeserializers(new CustomDeserializer())
.withSerializers(new CustomSerializer())
// Formats, locals, encoding, binary data
.withBinaryDataStrategy(BinaryDataStrategy.BASE_64_URL)
.withDateFormat("MM/dd/yyyy", Locale.ENGLISH)
.withLocale(Locale.CANADA)
.withEncoding("UTF-8")
.withStrictIJSON(true)
.withFormatting(true);
}
开发者ID:readlearncode,项目名称:JSON-framework-comparison,代码行数:35,代码来源:RuntimeSampler.java
示例3: customizedMapping
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
public String customizedMapping() {
JsonbConfig jsonbConfig = new JsonbConfig()
.withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES)
.withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL)
.withStrictIJSON(true)
.withFormatting(true)
.withNullValues(true);
Jsonb jsonb = JsonbBuilder.create(jsonbConfig);
return jsonb.toJson(book1);
}
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:14,代码来源:JsonBindingExample.java
示例4: allCustomizedMapping
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
public String allCustomizedMapping() {
PropertyVisibilityStrategy vis = new PropertyVisibilityStrategy() {
@Override
public boolean isVisible(Field field) {
return false;
}
@Override
public boolean isVisible(Method method) {
return false;
}
};
JsonbConfig jsonbConfig = new JsonbConfig()
.withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES)
.withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL)
.withPropertyVisibilityStrategy(vis)
.withStrictIJSON(true)
.withFormatting(true)
.withNullValues(true)
.withBinaryDataStrategy(BinaryDataStrategy.BASE_64_URL)
.withDateFormat("MM/dd/yyyy", Locale.ENGLISH);
Jsonb jsonb = JsonbBuilder.create(jsonbConfig);
return jsonb.toJson(book1);
}
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:29,代码来源:JsonBindingExample.java
示例5: givenLEXICOGRAPHICALPropertyOrderStrategy_shouldOrderLexicographically
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void givenLEXICOGRAPHICALPropertyOrderStrategy_shouldOrderLexicographically(){
String expectedJson = "{\"alternativeTitle\":\"01846537\",\"authorName\":{\"firstName\":\"Alex\",\"lastName\":\"Theedom\"},\"title\":\"Fun with JSON binding\"}";
JsonbConfig jsonbConfig = new JsonbConfig()
.withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL);
String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);
assertThat(actualJson).isEqualTo(expectedJson);
}
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:12,代码来源:CustomisePropertyOrderStrategyTest.java
示例6: givenANYPropertyOrderStrategy_shouldOrderLexicographically
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void givenANYPropertyOrderStrategy_shouldOrderLexicographically(){
String expectedJson = "{\"authorName\":{\"firstName\":\"Alex\",\"lastName\":\"Theedom\"},\"alternativeTitle\":\"01846537\",\"title\":\"Fun with JSON binding\"}";
JsonbConfig jsonbConfig = new JsonbConfig()
.withPropertyOrderStrategy(PropertyOrderStrategy.ANY);
String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);
assertThat(actualJson).isEqualTo(expectedJson);
}
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:12,代码来源:CustomisePropertyOrderStrategyTest.java
示例7: givenREVERSEPropertyOrderStrategy_shouldOrderLexicographically
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void givenREVERSEPropertyOrderStrategy_shouldOrderLexicographically(){
String expectedJson = "{\"title\":\"Fun with JSON binding\",\"authorName\":{\"lastName\":\"Theedom\",\"firstName\":\"Alex\"},\"alternativeTitle\":\"01846537\"}";
JsonbConfig jsonbConfig = new JsonbConfig()
.withPropertyOrderStrategy(PropertyOrderStrategy.REVERSE);
String actualJson = JsonbBuilder.create(jsonbConfig).toJson(magazine);
assertThat(actualJson).isEqualTo(expectedJson);
}
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:12,代码来源:CustomisePropertyOrderStrategyTest.java
示例8: testPropertySorting
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void testPropertySorting() {
FieldOrder fieldOrder = new FieldOrder();
Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL));
String expectedLexicographical = "{\"aField\":\"aValue\",\"bField\":\"bValue\",\"cField\":\"cValue\",\"dField\":\"dValue\"}";
assertEquals(expectedLexicographical, jsonb.toJson(fieldOrder));
jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.REVERSE));
String expectedReverse = "{\"dField\":\"dValue\",\"cField\":\"cValue\",\"bField\":\"bValue\",\"aField\":\"aValue\"}";
assertEquals(expectedReverse, jsonb.toJson(fieldOrder));
}
开发者ID:eclipse,项目名称:yasson,代码行数:12,代码来源:PropertyOrderTest.java
示例9: testPropertyCustomOrder
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void testPropertyCustomOrder() {
FieldCustomOrder fieldCustomOrder = new FieldCustomOrder();
Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL));
String expectedCustomOrder = "{\"aField\":\"aValue\",\"cField\":\"cValue\",\"dField\":\"dValue\",\"bField\":\"bValue\"}";
assertEquals(expectedCustomOrder, jsonb.toJson(fieldCustomOrder));
FieldCustomOrderWrapper fieldCustomOrderWrapper = new FieldCustomOrderWrapper();
String expectedOrder = "{\"fieldCustomOrder\":{\"aField\":\"aValue\",\"cField\":\"cValue\",\"dField\":\"dValue\",\"bField\":\"bValue\"},\"intField\":1,\"stringField\":\"stringValue\"}";
assertEquals(expectedOrder, jsonb.toJson(fieldCustomOrderWrapper));
}
开发者ID:eclipse,项目名称:yasson,代码行数:12,代码来源:PropertyOrderTest.java
示例10: testPropertySortingWithNamingAnnotation
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void testPropertySortingWithNamingAnnotation() {
FieldOrderNameAnnotation fieldOrderNameAnnotation = new FieldOrderNameAnnotation();
Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL));
String expectedLexicographical = "{\"bField\":\"bValue\",\"cField\":\"cValue\",\"dField\":\"dValue\",\"zField\":\"aValue\"}";
assertEquals(expectedLexicographical, jsonb.toJson(fieldOrderNameAnnotation));
jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.REVERSE));
String expectedReverse = "{\"zField\":\"aValue\",\"dField\":\"dValue\",\"cField\":\"cValue\",\"bField\":\"bValue\"}";
assertEquals(expectedReverse, jsonb.toJson(fieldOrderNameAnnotation));
}
开发者ID:eclipse,项目名称:yasson,代码行数:12,代码来源:PropertyOrderTest.java
示例11: testLexicographicalPropertyOrderRenamedProperties
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void testLexicographicalPropertyOrderRenamedProperties() {
JsonbConfig config = new JsonbConfig();
config.setProperty(JsonbConfig.PROPERTY_ORDER_STRATEGY, PropertyOrderStrategy.LEXICOGRAPHICAL);
Jsonb jsonb = JsonbBuilder.create(config);
String jsonString = jsonb.toJson(new RenamedPropertiesContainer() {{ setStringInstance("Test String"); setLongInstance(1); }});
Assert.assertTrue(jsonString.matches("\\{\\s*\"first\"\\s*\\:\\s*0\\s*,\\s*\"second\"\\s*\\:\\s*\"Test String\"\\s*,\\s*\"third\"\\s*\\:\\s*1\\s*\\}"));
RenamedPropertiesContainer unmarshalledObject = jsonb.fromJson("{ \"first\" : 1, \"second\" : \"Test String\", \"third\" : 1 }", RenamedPropertiesContainer.class);
Assert.assertEquals(3, unmarshalledObject.getIntInstance());
}
开发者ID:eclipse,项目名称:yasson,代码行数:13,代码来源:PropertyOrderTest.java
示例12: notYetPloymorphism
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void notYetPloymorphism() { // we run it since it checked list/item conversion
final Bar bar = new Bar();
bar.value = 11;
final Bar2 bar2 = new Bar2();
bar2.value = 21;
bar2.value2 = 22;
final Polymorphism foo = new Polymorphism();
foo.bars = new ArrayList<>(asList(bar, bar2));
final Jsonb jsonb = JsonbBuilder.create(
new JsonbConfig()
.setProperty("johnzon.readAttributeBeforeWrite", true)
.withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL) /* assertEquals() order */);
final String toString = jsonb.toJson(foo);
assertEquals("{\"bars\":[" +
"{\"type\":\"org.apache.johnzon.jsonb.AdapterTest$Bar\",\"value\":{\"value\":11}}," +
"{\"type\":\"org.apache.johnzon.jsonb.AdapterTest$Bar2\",\"value\":{\"value\":21,\"value2\":22}}]}", toString);
final Polymorphism read = jsonb.fromJson(toString, Polymorphism.class);
assertEquals(2, read.bars.size());
assertEquals(11, read.bars.get(0).value);
assertTrue(Bar.class == read.bars.get(0).getClass());
assertEquals(21, read.bars.get(1).value);
assertTrue(Bar2.class == read.bars.get(1).getClass());
assertEquals(22, Bar2.class.cast(read.bars.get(1)).value2);
}
开发者ID:apache,项目名称:johnzon,代码行数:31,代码来源:AdapterTest.java
示例13: orderComparator
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
private Comparator<String> orderComparator(final Class<?> clazz) {
final Comparator<String> keyComparator;
final JsonbPropertyOrder orderAnnotation = Meta.getAnnotation(clazz, JsonbPropertyOrder.class);
if (orderAnnotation != null) {
final List<String> indexed = new ArrayList<>(asList(orderAnnotation.value()));
if (naming != null) { // JsonbPropertyOrder applies on java names
for (int i = 0; i < indexed.size(); i++) {
indexed.set(i, naming.translateName(indexed.get(i)));
}
}
keyComparator = (o1, o2) -> {
final int i1 = indexed.indexOf(o1);
final int i2 = indexed.indexOf(o2);
if (i1 < 0) {
if (i2 < 0) {
if (order != null) {
switch (order) {
case PropertyOrderStrategy.LEXICOGRAPHICAL:
return o1.compareTo(o2);
case PropertyOrderStrategy.REVERSE:
return o2.compareTo(o1);
case PropertyOrderStrategy.ANY:
default:
return 1;
}
}
}
return 1;
}
return i1 - i2;
};
} else if (order != null) {
switch (order) {
case PropertyOrderStrategy.ANY:
keyComparator = null;
break;
case PropertyOrderStrategy.LEXICOGRAPHICAL:
keyComparator = String::compareTo;
break;
case PropertyOrderStrategy.REVERSE:
keyComparator = Comparator.reverseOrder();
break;
default:
keyComparator = null;
}
} else {
keyComparator = null;
}
return keyComparator;
}
开发者ID:apache,项目名称:johnzon,代码行数:51,代码来源:JsonbAccessMode.java
示例14: givenPropertyOrderStrategy_shouldSerialise
import javax.json.bind.config.PropertyOrderStrategy; //导入依赖的package包/类
@Test
public void givenPropertyOrderStrategy_shouldSerialise() {
JsonbConfig jsonbConfig = new JsonbConfig()
.withPropertyOrderStrategy(PropertyOrderStrategy.REVERSE);
String json = JsonbBuilder.create(jsonbConfig).toJson(new Book());
assertThat(json).isEqualTo("{\"authorName\":\"Alex Theedom\",\"bookPrice\":19.99,\"bookTitle\":\"Fun with JSON Binding\"}");
}
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:12,代码来源:PropertyOrderStrategyTest.java
注:本文中的javax.json.bind.config.PropertyOrderStrategy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论