public SerializeBeanInfo(Class<?> beanType, // JSONType jsonType, // String typeName, // String typeKey, int features, FieldInfo[] fields, // FieldInfo[] sortedFields ){ this.beanType = beanType; this.jsonType = jsonType; this.typeName = typeName; this.typeKey = typeKey; this.features = features; this.fields = fields; this.sortedFields = sortedFields; }
public static Class<?> getBuilderClass(Class<?> clazz, JSONType type) { if (clazz != null && clazz.getName().equals("org.springframework.security.web.savedrequest.DefaultSavedRequest")) { return TypeUtils.loadClass("org.springframework.security.web.savedrequest.DefaultSavedRequest$Builder"); } if (type == null) { return null; } Class<?> builderClass = type.builder(); if (builderClass == Void.class) { return null; } return builderClass; }
private static boolean isJSONTypeIgnore(Class<?> clazz, String propertyName) { JSONType jsonType = clazz.getAnnotation(JSONType.class); if (jsonType != null && jsonType.ignores() != null) { for (String item : jsonType.ignores()) { if (propertyName.equalsIgnoreCase(item)) { return true; } } } if (clazz.getSuperclass() != Object.class && clazz.getSuperclass() != null) { if (isJSONTypeIgnore(clazz.getSuperclass(), propertyName)) { return true; } } return false; }
private static boolean isJSONTypeIgnore(Class<?> clazz, String propertyName) { JSONType jsonType = clazz.getAnnotation(JSONType.class); if (jsonType != null && jsonType.ignores() != null) { for (String item : jsonType.ignores()) { if (propertyName.equalsIgnoreCase(item)) { return true; } } } if (clazz.getSuperclass() != Object.class) { if (isJSONTypeIgnore(clazz.getSuperclass(), propertyName)) { return true; } } return false; }
private static boolean isJSONTypeIgnore(Class<?> clazz, String propertyName){ JSONType jsonType = TypeUtils.getAnnotation(clazz,JSONType.class); if(jsonType != null){ // 1、新增 includes 支持,如果 JSONType 同时设置了includes 和 ignores 属性,则以includes为准。 // 2、个人认为对于大小写敏感的Java和JS而言,使用 equals() 比 equalsIgnoreCase() 更好,改动的唯一风险就是向后兼容性的问题 // 不过,相信开发者应该都是严格按照大小写敏感的方式进行属性设置的 String[] fields = jsonType.includes(); if(fields.length > 0){ for(int i = 0; i < fields.length; i++){ if(propertyName.equals(fields[i])){ return false; } } return true; } else{ fields = jsonType.ignores(); for(int i = 0; i < fields.length; i++){ if(propertyName.equals(fields[i])){ return true; } } } } if(clazz.getSuperclass() != Object.class && clazz.getSuperclass() != null){ if(isJSONTypeIgnore(clazz.getSuperclass(), propertyName)){ return true; } } return false; }
public static int getSerializeFeatures(Class<?> clazz){ JSONType annotation = TypeUtils.getAnnotation(clazz,JSONType.class); if(annotation == null){ return 0; } return SerializerFeature.of(annotation.serialzeFeatures()); }
public static int getParserFeatures(Class<?> clazz){ JSONType annotation = TypeUtils.getAnnotation(clazz,JSONType.class); if(annotation == null){ return 0; } return Feature.of(annotation.parseFeatures()); }
public ObjectSerializer createJavaBeanSerializer(Class<?> clazz) { if (!Modifier.isPublic(clazz.getModifiers())) { return new JavaBeanSerializer(clazz); } boolean asm = this.asm; if ((asm && this.asmFactory.isExternalClass(clazz)) || clazz == Serializable.class || clazz == Object.class) { asm = false; } JSONType annotation = (JSONType) clazz.getAnnotation(JSONType.class); if (!(annotation == null || annotation.asm())) { asm = false; } if (asm && !ASMUtils.checkName(clazz.getName())) { asm = false; } if (asm) { try { ObjectSerializer asmSerializer = createASMSerializer(clazz); if (asmSerializer != null) { return asmSerializer; } } catch (ClassCastException e) { } catch (Throwable e2) { JSONException jSONException = new JSONException("create asm serializer error, class " + clazz, e2); } } return new JavaBeanSerializer(clazz); }
private static boolean isJSONTypeIgnore(Class<?> clazz, String propertyName) { JSONType jsonType = (JSONType) clazz.getAnnotation(JSONType.class); if (!(jsonType == null || jsonType.ignores() == null)) { for (String item : jsonType.ignores()) { if (propertyName.equalsIgnoreCase(item)) { return true; } } } if (clazz.getSuperclass() == Object.class || clazz.getSuperclass() == null || !isJSONTypeIgnore(clazz.getSuperclass(), propertyName)) { return false; } return true; }
public static int getSerializeFeatures(Class<?> clazz) { JSONType annotation = (JSONType) clazz.getAnnotation(JSONType.class); if (annotation == null) { return 0; } return SerializerFeature.of(annotation.serialzeFeatures()); }
public static int getParserFeatures(Class<?> clazz) { JSONType annotation = (JSONType) clazz.getAnnotation(JSONType.class); if (annotation == null) { return 0; } return Feature.of(annotation.parseFeatures()); }
private static boolean isJSONTypeIgnore(Class<?> clazz, String propertyName) { JSONType jsonType = clazz.getAnnotation(JSONType.class); if (jsonType != null) { // 1、新增 includes 支持,如果 JSONType 同时设置了includes 和 ignores 属性,则以includes为准。 // 2、个人认为对于大小写敏感的Java和JS而言,使用 equals() 比 equalsIgnoreCase() 更好,改动的唯一风险就是向后兼容性的问题 // 不过,相信开发者应该都是严格按照大小写敏感的方式进行属性设置的 String[] fields = jsonType.includes(); if (fields.length > 0) { for (int i = 0; i < fields.length; i++) { if (propertyName.equals(fields[i])) { return false; } } return true; } else { fields = jsonType.ignores(); for (int i = 0; i < fields.length; i++) { if (propertyName.equals(fields[i])) { return true; } } } } if (clazz.getSuperclass() != Object.class && clazz.getSuperclass() != null) { if (isJSONTypeIgnore(clazz.getSuperclass(), propertyName)) { return true; } } return false; }
public static int getSerializeFeatures(Class<?> clazz) { JSONType annotation = clazz.getAnnotation(JSONType.class); if (annotation == null) { return 0; } return SerializerFeature.of(annotation.serialzeFeatures()); }
public static int getParserFeatures(Class<?> clazz) { JSONType annotation = clazz.getAnnotation(JSONType.class); if (annotation == null) { return 0; } return Feature.of(annotation.parseFeatures()); }
public static List<FieldInfo> computeGetters(Class<?> clazz, Map<String,String> aliasMap, boolean sorted){ JSONType jsonType = TypeUtils.getAnnotation(clazz,JSONType.class); Map<String,Field> fieldCacheMap = new HashMap<String,Field>(); ParserConfig.parserAllFieldToCache(clazz, fieldCacheMap); return computeGetters(clazz, jsonType, aliasMap, fieldCacheMap, sorted, PropertyNamingStrategy.CamelCase); }
public static Class<?> getBuilderClass(JSONType type) { return getBuilderClass(null, type); }
public static JSONType getJSONType(Class<?> clazz) { return (JSONType) clazz.getAnnotation(JSONType.class); }
public static JSONType getJSONType(Class<?> clazz) { return clazz.getAnnotation(JSONType.class); }