Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
新建 ArrayExcludePropertyNamesPropertyFilter fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
venusdrogon committed Jan 20, 2018
1 parent 16188fc commit 1e138ac
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import net.sf.json.util.PropertyFilter;

/**
* The Class ArrayContainsPropertyFilter.
* java to json 时候的 属性过滤器.
*
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @since 1.2.2
* @since 1.11.0 change package
*/
class ArrayContainsPropertyNamesPropertyFilter implements PropertyFilter{

Expand All @@ -40,6 +41,8 @@ public ArrayContainsPropertyNamesPropertyFilter(String...propertyNames){
this.propertyNames = propertyNames;
}

//---------------------------------------------------------------

/*
* (non-Javadoc)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2008 feilong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.json.jsonlib.builder;

import net.sf.json.util.PropertyFilter;

/**
* 排除属性过滤器.
*
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @since 1.11.0
*/
class ArrayExcludePropertyNamesPropertyFilter implements PropertyFilter{

/** The property names. */
private final String[] propertyNames;

//---------------------------------------------------------------

/**
* The Constructor.
*
* @param propertyNames
* the property names
*/
public ArrayExcludePropertyNamesPropertyFilter(String...propertyNames){
this.propertyNames = propertyNames;
}

//---------------------------------------------------------------

/*
* (non-Javadoc)
*
* @see net.sf.json.util.PropertyFilter#apply(java.lang.Object, java.lang.String, java.lang.Object)
*/
@Override
public boolean apply(Object source,String name,Object value){
// [source] the owner of the property
// [name] the name of the property
// [value] the value of the property
return org.apache.commons.lang3.ArrayUtils.contains(propertyNames, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ public static JsonConfig build(Class<?> rootClass,JsonToJavaConfig jsonToJavaCon

// Ignore missing properties with Json-Lib

// 避免出现 Unknown property 'orderIdAndCodeMap' on class 'class
// com.baozun.trade.web.controller.payment.result.command.PaymentResultEntity' 异常
// 避免出现 Unknown property 'orderIdAndCodeMap' on class 'class com.baozun.trade.web.result.command.PaymentResultEntity' 异常
jsonConfig.setPropertySetStrategy(new PropertyStrategyWrapper(PropertySetStrategy.DEFAULT));

//---------------------------------------------------------------
//排除
String[] excludes = jsonToJavaConfig.getExcludes();
if (isNotNullOrEmpty(excludes)){
jsonConfig.setJavaPropertyFilter(new ArrayExcludePropertyNamesPropertyFilter(excludes));
}
return jsonConfig;
}
}

0 comments on commit 1e138ac

Please sign in to comment.