本文整理汇总了Java中com.fasterxml.jackson.annotation.JsonPropertyOrder类的典型用法代码示例。如果您正苦于以下问题:Java JsonPropertyOrder类的具体用法?Java JsonPropertyOrder怎么用?Java JsonPropertyOrder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonPropertyOrder类属于com.fasterxml.jackson.annotation包,在下文中一共展示了JsonPropertyOrder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: annotationStyleGsonProducesGsonAnnotations
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void annotationStyleGsonProducesGsonAnnotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException, NoSuchFieldException {
Class generatedType = schemaRule.generateAndCompile("/json/examples/torrent.json", "com.example",
config("annotationStyle", "gson",
"propertyWordDelimiters", "_",
"sourceType", "json"))
.loadClass("com.example.Torrent");
assertThat(schemaRule.getGenerateDir(), not(containsText("org.codehaus.jackson")));
assertThat(schemaRule.getGenerateDir(), not(containsText("com.fasterxml.jackson")));
assertThat(schemaRule.getGenerateDir(), containsText("com.google.gson"));
assertThat(schemaRule.getGenerateDir(), containsText("@SerializedName"));
Method getter = generatedType.getMethod("getBuild");
assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(nullValue()));
assertThat(generatedType.getAnnotation(JsonInclude.class), is(nullValue()));
assertThat(getter.getAnnotation(JsonProperty.class), is(nullValue()));
}
示例2: annotationStyleMoshi1ProducesMoshi1Annotations
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void annotationStyleMoshi1ProducesMoshi1Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException, NoSuchFieldException {
Class generatedType = schemaRule.generateAndCompile("/json/examples/torrent.json", "com.example",
config("annotationStyle", "moshi1",
"propertyWordDelimiters", "_",
"sourceType", "json"))
.loadClass("com.example.Torrent");
assertThat(schemaRule.getGenerateDir(), not(containsText("org.codehaus.jackson")));
assertThat(schemaRule.getGenerateDir(), not(containsText("com.fasterxml.jackson")));
assertThat(schemaRule.getGenerateDir(), not(containsText("com.google.gson")));
assertThat(schemaRule.getGenerateDir(), not(containsText("@SerializedName")));
assertThat(schemaRule.getGenerateDir(), containsText("com.squareup.moshi"));
assertThat(schemaRule.getGenerateDir(), containsText("@Json"));
Method getter = generatedType.getMethod("getBuild");
assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(nullValue()));
assertThat(generatedType.getAnnotation(JsonInclude.class), is(nullValue()));
assertThat(getter.getAnnotation(JsonProperty.class), is(nullValue()));
}
示例3: annotationStyleJackson2ProducesJackson2Annotations
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void annotationStyleJackson2ProducesJackson2Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
Class generatedType = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
config("annotationStyle", "jackson2"))
.loadClass("com.example.PrimitiveProperties");
assertThat(schemaRule.getGenerateDir(), not(containsText("org.codehaus.jackson")));
assertThat(schemaRule.getGenerateDir(), containsText("com.fasterxml.jackson"));
Method getter = generatedType.getMethod("getA");
assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(JsonInclude.class), is(notNullValue()));
assertThat(getter.getAnnotation(JsonProperty.class), is(notNullValue()));
}
示例4: annotationStyleJackson1ProducesJackson1Annotations
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void annotationStyleJackson1ProducesJackson1Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
Class generatedType = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
config("annotationStyle", "jackson1"))
.loadClass("com.example.PrimitiveProperties");
assertThat(schemaRule.getGenerateDir(), not(containsText("com.fasterxml.jackson")));
assertThat(schemaRule.getGenerateDir(), containsText("org.codehaus.jackson"));
Method getter = generatedType.getMethod("getA");
assertThat(generatedType.getAnnotation(org.codehaus.jackson.annotate.JsonPropertyOrder.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(org.codehaus.jackson.map.annotate.JsonSerialize.class), is(notNullValue()));
assertThat(getter.getAnnotation(org.codehaus.jackson.annotate.JsonProperty.class), is(notNullValue()));
}
示例5: customAnnotatorCanBeAppliedAlongsideCoreAnnotator
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void customAnnotatorCanBeAppliedAlongsideCoreAnnotator() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
config("customAnnotator", DeprecatingAnnotator.class.getName()));
Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");
Method getter = generatedType.getMethod("getA");
assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(JsonInclude.class), is(notNullValue()));
assertThat(getter.getAnnotation(JsonProperty.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(Deprecated.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(Deprecated.class), is(notNullValue()));
assertThat(getter.getAnnotation(Deprecated.class), is(notNullValue()));
}
示例6: build
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
public ResourceInformation build(Class<?> resourceClass, boolean allowNonResourceBaseClass) {
List<ResourceField> resourceFields = getResourceFields(resourceClass);
String resourceType = getResourceType(resourceClass, allowNonResourceBaseClass);
Optional<JsonPropertyOrder> propertyOrder = ClassUtils.getAnnotation(resourceClass, JsonPropertyOrder.class);
if (propertyOrder.isPresent()) {
JsonPropertyOrder propertyOrderAnnotation = propertyOrder.get();
Collections.sort(resourceFields, new FieldOrderedComparator(propertyOrderAnnotation.value(), propertyOrderAnnotation.alphabetic()));
}
DefaultResourceInstanceBuilder<?> instanceBuilder = new DefaultResourceInstanceBuilder(resourceClass);
Class<?> superclass = resourceClass.getSuperclass();
String superResourceType = superclass != Object.class && context.accept(superclass) ? context.getResourceType(superclass) : null;
ResourceInformation information = new ResourceInformation(context.getTypeParser(), resourceClass, resourceType, superResourceType, instanceBuilder,
resourceFields);
if (!allowNonResourceBaseClass && information.getIdField() == null) {
throw new ResourceIdNotFoundException(resourceClass.getCanonicalName());
}
return information;
}
示例7: orderedFields
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
protected List<Element> orderedFields() {
TypeElement typeElement = (TypeElement) typeUtils.asElement(beanType);
final List<Element> orderedProperties = new ArrayList<>();
final List<Element> fields = typeElement.getEnclosedElements().stream().filter(e -> ElementKind.FIELD
.equals(e.getKind()) && !e.getModifiers()
.contains(Modifier.STATIC)).collect(Collectors.toList());
Optional.ofNullable(typeUtils.asElement(beanType).getAnnotation(JsonPropertyOrder.class))
.ifPresent(jsonPropertyOrder -> {
final List<String> orderedFieldsNames = Arrays.asList(jsonPropertyOrder.value());
orderedProperties.addAll(fields.stream()
.filter(f -> orderedFieldsNames.contains(f.getSimpleName().toString()))
.collect(Collectors.toList()));
fields.removeAll(orderedProperties);
if (jsonPropertyOrder.alphabetic()) {
fields.sort(Comparator.comparing(f -> f.getSimpleName().toString()));
}
fields.addAll(0, orderedProperties);
});
return fields;
}
示例8: build
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public ResourceInformation build(Class<?> resourceClass) {
List<AnnotatedResourceField> resourceFields = getResourceFields(resourceClass);
String resourceType = getResourceType(resourceClass);
Optional<JsonPropertyOrder> propertyOrder = ClassUtils.getAnnotation(resourceClass, JsonPropertyOrder.class);
if (propertyOrder.isPresent()) {
JsonPropertyOrder propertyOrderAnnotation = propertyOrder.get();
Collections.sort(resourceFields, new FieldOrderedComparator(propertyOrderAnnotation.value(), propertyOrderAnnotation.alphabetic()));
}
DefaultResourceInstanceBuilder<?> instanceBuilder = new DefaultResourceInstanceBuilder(resourceClass);
Class<?> superclass = resourceClass.getSuperclass();
String superResourceType = superclass != Object.class && context.accept(superclass) ? context.getResourceType(superclass) : null;
return new ResourceInformation(context.getTypeParser(), resourceClass, resourceType, superResourceType, instanceBuilder, (List) resourceFields);
}
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:20,代码来源:AnnotationResourceInformationBuilder.java
示例9: annotationStyleJackson2ProducesJackson2Annotations
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void annotationStyleJackson2ProducesJackson2Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
File generatedOutputDirectory = generate("/schema/properties/primitiveProperties.json", "com.example",
config("annotationStyle", "jackson2"));
assertThat(generatedOutputDirectory, not(containsText("org.codehaus.jackson")));
assertThat(generatedOutputDirectory, containsText("com.fasterxml.jackson"));
ClassLoader resultsClassLoader = compile(generatedOutputDirectory);
Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");
Method getter = generatedType.getMethod("getA");
assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(JsonInclude.class), is(notNullValue()));
assertThat(getter.getAnnotation(JsonProperty.class), is(notNullValue()));
}
示例10: annotationStyleJackson1ProducesJackson1Annotations
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void annotationStyleJackson1ProducesJackson1Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
File generatedOutputDirectory = generate("/schema/properties/primitiveProperties.json", "com.example",
config("annotationStyle", "jackson1"));
assertThat(generatedOutputDirectory, not(containsText("com.fasterxml.jackson")));
assertThat(generatedOutputDirectory, containsText("org.codehaus.jackson"));
ClassLoader resultsClassLoader = compile(generatedOutputDirectory);
Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");
Method getter = generatedType.getMethod("getA");
assertThat(generatedType.getAnnotation(org.codehaus.jackson.annotate.JsonPropertyOrder.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(org.codehaus.jackson.map.annotate.JsonSerialize.class), is(notNullValue()));
assertThat(getter.getAnnotation(org.codehaus.jackson.annotate.JsonProperty.class), is(notNullValue()));
}
示例11: customAnnotatorCanBeAppliedAlongsideCoreAnnotator
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void customAnnotatorCanBeAppliedAlongsideCoreAnnotator() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
ClassLoader resultsClassLoader = generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
config("customAnnotator", DeprecatingAnnotator.class.getName()));
Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");
Method getter = generatedType.getMethod("getA");
assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(JsonInclude.class), is(notNullValue()));
assertThat(getter.getAnnotation(JsonProperty.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(Deprecated.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(Deprecated.class), is(notNullValue()));
assertThat(getter.getAnnotation(Deprecated.class), is(notNullValue()));
}
示例12: propertyOrder
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Override
public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) {
JAnnotationArrayMember annotationValue = clazz.annotate(JsonPropertyOrder.class).paramArray("value");
for (Iterator<String> properties = propertiesNode.fieldNames(); properties.hasNext();) {
annotationValue.param(properties.next());
}
}
示例13: defaultAnnotationStyeIsJackson2
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void defaultAnnotationStyeIsJackson2() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example");
Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");
Method getter = generatedType.getMethod("getA");
assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(JsonInclude.class), is(notNullValue()));
assertThat(getter.getAnnotation(JsonProperty.class), is(notNullValue()));
}
示例14: annotationStyleJacksonProducesJackson2Annotations
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void annotationStyleJacksonProducesJackson2Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
config("annotationStyle", "jackson"));
Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");
Method getter = generatedType.getMethod("getA");
assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(notNullValue()));
assertThat(generatedType.getAnnotation(JsonInclude.class), is(notNullValue()));
assertThat(getter.getAnnotation(JsonProperty.class), is(notNullValue()));
}
示例15: onGetAnnotationShouldReturnParentAnnotation
import com.fasterxml.jackson.annotation.JsonPropertyOrder; //导入依赖的package包/类
@Test
public void onGetAnnotationShouldReturnParentAnnotation() {
// WHEN
Optional<JsonPropertyOrder> result = ClassUtils.getAnnotation(ChildClass.class, JsonPropertyOrder.class);
// THEN
assertThat(result.get()).isInstanceOf(JsonPropertyOrder.class);
}