BeanToMapConvertor implements Cloneable { @SuppressWarnings("unchecked") public Map<String, Object> toMap(final Object obj){ if (obj == null) return Collections.emptyMap(); if(obj.getClass().isArray()) return CUtils.asMap((Object[])obj); if(obj instanceof Map) return (Map<String, Object>)obj; ObjectWrapper objWrapper = objectWrapper(obj); PropertyDescriptor[] props = objWrapper.desribProperties(); if (props == null || props.length == 0) return Collections.emptyMap(); Map<String, Object> rsMap = new HashMap<>(); Object val = null; for (PropertyDescriptor prop : props) { val = objWrapper.getPropertyValue(prop); ObjectPropertyContext propContext = createPropertyContext(obj, prop, null); if (propertyAcceptor==null || propertyAcceptor.apply(propContext, val)){ val = convertValue(prop, val); rsMap.put(toPropertyName(propContext.getConvertedName()), val); } } return rsMap; }  void setPropertyAccesor(String propertyAccesor); @Override BeanToMapConvertor clone(); void setPrefix(String prefix); void setPropertyAcceptor(PropertyAcceptor propertyAcceptor); void setValueConvertor(BiFunction<PropertyDescriptor, Object, Object> valueConvertor); void setFlatableObject(Function<Object, Boolean> flatableObject); void setPropertyNameConvertor(PropertyNameConvertor propertyNameConvertor); void setListOpener(String listOpener); void setListCloser(String listCloser); @SuppressWarnings("unchecked") Map<String, Object> toMap(final Object obj); Map<String, Object> toFlatMap(final Object obj); boolean isMappableValue(Object value); void toFlatMap(final Map<String, Object> params, final Object obj); void flatObject(final String prefixName, final Object obj, ValuePutter valuePutter); final static Function<Object, Boolean> DEFAULT_FLATABLE; }
@Test public void testWithExcludeOnly(){ UserEntity user = new UserEntity(); user.setId(11L); user.setUserName("testUserName"); Map<String, Object> map = BeanToMapBuilder.newBuilder() .enableFieldNameAnnotation() .excludeProperties("roles", "role") .build() .toMap(user); System.out.println("map: " + map); assertThat(map.toString()).isEqualTo("{birthDay=null, id=11, userName=testUserName, age=0, email=null, height=0.0, status=null}"); }