List of usage examples for com.google.gson FieldAttributes getName
public String getName()
From source file:com.gst.infrastructure.core.api.ParameterListInclusionStrategy.java
License:Apache License
@Override public boolean shouldSkipField(final FieldAttributes f) { return !this.parameterNamesToInclude.contains(f.getName()); }
From source file:com.ilearnrw.reader.types.LogBasicExclusionStrategy.java
License:Open Source License
@Override public boolean shouldSkipField(FieldAttributes f) { if (f.getDeclaringClass() == c) { for (int i = 0; i < fieldNames.size(); i++) { if (f.getName().equals(fieldNames.get(i))) return true; }//from ww w .j a va 2 s . co m } return false; }
From source file:com.intuit.wasabi.tests.library.util.serialstrategies.DefaultNameExclusionStrategy.java
License:Apache License
/** * Skips fields if their names are on the blacklist. * * @param fieldAttributes the field attributes * @return true if the field name is in the blacklist *///w ww .ja va 2 s . c om @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { return blacklist.contains(fieldAttributes.getName()); }
From source file:com.intuit.wasabi.tests.library.util.serialstrategies.DefaultNameInclusionStrategy.java
License:Apache License
/** * Skips all fields if their names are not contained in the whitelist. * * @param fieldAttributes the field attributes * @return false if the whitelist contains the field name *//*w w w. j ava2 s .c o m*/ @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { return !whitelist.contains(fieldAttributes.getName()); }
From source file:com.jd.survey.service.util.JsonHelperService.java
License:Open Source License
public String serializeSurveyDefinition(SurveyDefinition surveyDefinition) { try {// w w w.j a v a 2 s .c o m GsonBuilder gsonBuilder = new GsonBuilder(); //set up the fields to skip in the serialization gsonBuilder = gsonBuilder.setExclusionStrategies(new ExclusionStrategy() { public boolean shouldSkipClass(Class<?> clazz) { return false; } @Override public boolean shouldSkipField(FieldAttributes f) { boolean skip = (f.getDeclaringClass() == SurveyDefinition.class && f.getName().equals("id")) || (f.getDeclaringClass() == SurveyDefinition.class && f.getName().equals("version")) || (f.getDeclaringClass() == SurveyDefinition.class && f.getName().equals("department")) || (f.getDeclaringClass() == SurveyDefinition.class && f.getName().equals("users")) || (f.getDeclaringClass() == SurveyDefinitionPage.class && f.getName().equals("id")) || (f.getDeclaringClass() == SurveyDefinitionPage.class && f.getName().equals("surveyDefinition")) || (f.getDeclaringClass() == Question.class && f.getName().equals("id")) || (f.getDeclaringClass() == Question.class && f.getName().equals("version")) || (f.getDeclaringClass() == Question.class && f.getName().equals("page")) || (f.getDeclaringClass() == Question.class && f.getName().equals("optionsList")) || (f.getDeclaringClass() == Question.class && f.getName().equals("rowLabelsList")) || (f.getDeclaringClass() == Question.class && f.getName().equals("columnLabelsList")) || (f.getDeclaringClass() == QuestionOption.class && f.getName().equals("id")) || (f.getDeclaringClass() == QuestionOption.class && f.getName().equals("version")) || (f.getDeclaringClass() == QuestionOption.class && f.getName().equals("question")) || (f.getDeclaringClass() == QuestionRowLabel.class && f.getName().equals("id")) || (f.getDeclaringClass() == QuestionRowLabel.class && f.getName().equals("version")) || (f.getDeclaringClass() == QuestionRowLabel.class && f.getName().equals("question")) || (f.getDeclaringClass() == QuestionColumnLabel.class && f.getName().equals("id")) || (f.getDeclaringClass() == QuestionColumnLabel.class && f.getName().equals("version")) || (f.getDeclaringClass() == QuestionColumnLabel.class && f.getName().equals("question")); return skip; } }); //de-proxy the object gsonBuilder.registerTypeHierarchyAdapter(HibernateProxy.class, new HibernateProxySerializer()); Hibernate.initialize(surveyDefinition); if (surveyDefinition instanceof HibernateProxy) { surveyDefinition = (SurveyDefinition) ((HibernateProxy) surveyDefinition) .getHibernateLazyInitializer().getImplementation(); } Gson gson = gsonBuilder.serializeNulls().create(); return gson.toJson(surveyDefinition); } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.NowwebmanagerController.java
License:Open Source License
@Override public boolean shouldSkipField(FieldAttributes fieldattributes) { Class<?> owner = fieldattributes.getDeclaringClass(); Class<?> c = fieldattributes.getDeclaredClass(); String f = fieldattributes.getName(); boolean isSkip = false; if (owner == target) { if (ArrayUtils.contains(fields, f)) { log.debug("fitler field:{} for class:{}", f, owner); isSkip = true;/*from w ww . j a va 2 s . c o m*/ } if (ArrayUtils.contains(clazz, c)) { log.debug("fitler class:{} for class:{}", c, owner); isSkip = true; } if (reverse) { isSkip = !isSkip; } } return isSkip; }
From source file:com.nouveauxterritoires.eterritoires.identityserver.openid.connect.view.TaxeUserInfoViewForAdmins.java
License:Apache License
/** * @return//from w ww .ja v a 2 s .c o m */ @Override protected ExclusionStrategy getExclusionStrategy() { return new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes f) { if (blacklistedFields.contains(f.getName())) { return true; } else { return false; } } @Override public boolean shouldSkipClass(Class<?> clazz) { // skip the JPA binding wrapper if (clazz.equals(BeanPropertyBindingResult.class)) { return true; } return false; } }; }
From source file:com.nouveauxterritoires.eterritoires.identityserver.openid.connect.view.TaxeUserInfoViewForUsers.java
License:Apache License
@Override protected ExclusionStrategy getExclusionStrategy() { return new ExclusionStrategy() { @Override/*from w w w . ja v a2 s . c o m*/ public boolean shouldSkipField(FieldAttributes f) { // whitelist the handful of fields that are good if (whitelistedFields.contains(f.getName())) { return false; } else { return true; } } @Override public boolean shouldSkipClass(Class<?> clazz) { // skip the JPA binding wrapper if (clazz.equals(BeanPropertyBindingResult.class)) { return true; } return false; } }; }
From source file:com.shazam.shazamcrest.matcher.GsonProvider.java
License:Apache License
private static void registerExclusionStrategies(GsonBuilder gsonBuilder, final List<Class<?>> typesToIgnore, final List<Matcher<String>> fieldsToIgnore) { if (typesToIgnore.isEmpty() && fieldsToIgnore.isEmpty()) { return;//from www. j a va 2 s.com } gsonBuilder.setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes f) { for (Matcher<String> p : fieldsToIgnore) { if (p.matches(f.getName())) { return true; } } return false; } @Override public boolean shouldSkipClass(Class<?> clazz) { return (typesToIgnore.contains(clazz)); } }); }
From source file:com.thoughtworks.go.server.service.PipelineService.java
License:Apache License
private ExclusionStrategy getGsonExclusionStrategy() { return new ExclusionStrategy() { @Override/*from w ww . ja v a 2s . c o m*/ public boolean shouldSkipField(FieldAttributes f) { return f.getName().equals("materialConfig") || f.getName().equals("parents") || f.getName().equals("children"); } @Override public boolean shouldSkipClass(Class<?> clazz) { return false; } }; }