Java Code Examples for com.fasterxml.jackson.annotation.JsonCreator#mode()

The following examples show how to use com.fasterxml.jackson.annotation.JsonCreator#mode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringToEnumConverter.java    From mica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nullable
private static AccessibleObject getAnnotation(Class<?> clazz) {
	Set<AccessibleObject> accessibleObjects = new HashSet<>();
	// JsonCreator METHOD, CONSTRUCTOR
	Constructor<?>[] constructors = clazz.getConstructors();
	Collections.addAll(accessibleObjects, constructors);
	// methods
	Method[] methods = clazz.getDeclaredMethods();
	Collections.addAll(accessibleObjects, methods);
	for (AccessibleObject accessibleObject : accessibleObjects) {
		// 复用 jackson 的 JsonCreator注解
		JsonCreator jsonCreator = accessibleObject.getAnnotation(JsonCreator.class);
		if (jsonCreator != null && JsonCreator.Mode.DISABLED != jsonCreator.mode()) {
			accessibleObject.setAccessible(true);
			return accessibleObject;
		}
	}
	return null;
}
 
Example 2
Source File: StringToEnumConverter.java    From blade-tool with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nullable
private static AccessibleObject getAnnotation(Class<?> clazz) {
	Set<AccessibleObject> accessibleObjects = new HashSet<>();
	// JsonCreator METHOD, CONSTRUCTOR
	Constructor<?>[] constructors = clazz.getConstructors();
	Collections.addAll(accessibleObjects, constructors);
	// methods
	Method[] methods = clazz.getDeclaredMethods();
	Collections.addAll(accessibleObjects, methods);
	for (AccessibleObject accessibleObject : accessibleObjects) {
		// 复用 jackson 的 JsonCreator注解
		JsonCreator jsonCreator = accessibleObject.getAnnotation(JsonCreator.class);
		if (jsonCreator != null && JsonCreator.Mode.DISABLED != jsonCreator.mode()) {
			accessibleObject.setAccessible(true);
			return accessibleObject;
		}
	}
	return null;
}