Skip to content

Commit

Permalink
Merge pull request alibaba#329 from CodePlayer/master
Browse files Browse the repository at this point in the history
add includes support in JSONType
  • Loading branch information
wenshao committed May 6, 2015
2 parents 64047cd + b0ce3c8 commit 1b7f8dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/alibaba/fastjson/annotation/JSONType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
boolean asm() default true;

String[] orders() default {};


String[] includes() default {};

String[] ignores() default {};

SerializerFeature[] serialzeFeatures() default {};
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/com/alibaba/fastjson/util/TypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1267,10 +1267,24 @@ public static JSONField getSupperMethodAnnotation(Class<?> clazz, Method method)
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 (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;
}
}
}
}
Expand Down

0 comments on commit 1b7f8dc

Please sign in to comment.