List of usage examples for com.google.gson FieldAttributes getName
public String getName()
From source file:org.gisho.spring.config.GsonConfiguration.java
@Bean @ConditionalOnMissingBean//w w w. j a v a 2 s . co m public Gson gson() { Gson gson = new GsonBuilder().addSerializationExclusionStrategy(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes field) { return field.getName().equals("echantillonList") || field.getName().equals("cofisemUserList") || field.getName().equals("spiUserList") || field.getName().equals("userRoleSet") || field.getName().equals("password"); } @Override public boolean shouldSkipClass(Class<?> arg0) { return false; } }).serializeNulls().setDateFormat("dd/MM/yyyy").create(); return gson; }
From source file:org.jboss.aerogear.android.impl.unifiedpush.AeroGearGCMPushRegistrar.java
License:Apache License
@Override public void register(final Context context, final Callback<Void> callback) { new AsyncTask<Void, Void, Exception>() { @Override//from w ww. j a v a 2s .com protected Exception doInBackground(Void... params) { try { if (gcm == null) { gcm = gcmProvider.get(context); } String regid = getRegistrationId(context); if (regid.length() == 0) { regid = gcm.register(config.senderIds.toArray(new String[] {})); AeroGearGCMPushRegistrar.this.setRegistrationId(context, regid); } config.setDeviceToken(regid); URL deviceRegistryURL = UrlUtils.appendToBaseURL(pushServerURI.toURL(), registryDeviceEndpoint); HttpRestProviderForPush httpProvider = httpProviderProvider.get(deviceRegistryURL, TIMEOUT); httpProvider.setPasswordAuthentication(config.getVariantID(), config.getSecret()); Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() { private final ImmutableSet<String> fields; { fields = ImmutableSet.<String>builder().add("deviceToken").add("deviceType") .add("alias").add("operatingSystem").add("osVersion").add("categories").build(); } @Override public boolean shouldSkipField(FieldAttributes f) { return !(f.getDeclaringClass() == PushConfig.class && fields.contains(f.getName())); } @Override public boolean shouldSkipClass(Class<?> arg0) { return false; } }).create(); try { httpProvider.post(gson.toJson(config)); return null; } catch (HttpException ex) { return ex; } } catch (Exception ex) { return ex; } } @SuppressWarnings("unchecked") @Override protected void onPostExecute(Exception result) { if (result == null) { callback.onSuccess(null); } else { callback.onFailure(result); } }; }.execute((Void) null); }
From source file:org.opendaylight.tsdr.persistence.elasticsearch.ElasticsearchStore.java
License:Open Source License
/** * Built a client configuration also base on properties file. *///from ww w . j a va 2s.c om private HttpClientConfig buildClientConfig() throws IOException { GsonBuilder gson = new GsonBuilder().setFieldNamingStrategy(field -> { String name = FieldNamingPolicy.UPPER_CAMEL_CASE.translateName(field); if (name.startsWith("_")) { return name.substring(1); } return name; }).setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { String name = fieldAttributes.getName().toLowerCase(); return name.equals("hash") || name.equals("hashvalid"); } @Override public boolean shouldSkipClass(Class<?> clazz) { return false; } }); String serverUrl = properties.get("serverUrl"); HttpClientConfig.Builder configBuilder = new HttpClientConfig.Builder(serverUrl).multiThreaded(true) .gson(gson.create()); if (Boolean.valueOf(properties.get("nodeDiscovery"))) { configBuilder.discoveryEnabled(true).discoveryFrequency(1L, TimeUnit.MINUTES); } String username = properties.get("username"); String password = properties.get("password"); if (!Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password)) { configBuilder.defaultCredentials(username, password); } return configBuilder.build(); }
From source file:org.smartparam.serializer.metadata.PropertyExclusionStrategy.java
License:Apache License
@Override public boolean shouldSkipField(FieldAttributes field) { return propertiesToExclude.contains(field.getName()); }
From source file:org.wso2.carbon.apimgt.impl.soaptorest.util.SwaggerFieldsExcludeStrategy.java
License:Open Source License
@Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { return fieldAttributes.getName().equals("vendorExtensions"); }
From source file:se.liu.imt.mi.eee.validation.json.AOMtoJSONandYAMLSerializer.java
License:LGPL
/** * Create an outputter with default encoding, indent and lineSeparator * TODO: fix node_i_d --> node_id//from w w w .j a v a2 s . co m */ public AOMtoJSONandYAMLSerializer() { this.encoding = UTF8; this.indent = " "; // 4 white space characters this.lineSeparator = "\r\n"; gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setExclusionStrategies(new ExclusionStrategy() { public boolean shouldSkipClass(Class<?> clazz) { if (clazz == Archetype.class) return true; // Avoid circular reference return false; } /* Custom field exclusion goes here */ public boolean shouldSkipField(FieldAttributes f) { //System.out.println("---> "+f.getName()); if (f.getName().equalsIgnoreCase("termDefinitionMap")) return true; if (f.getName().equalsIgnoreCase("constraintDefinitionMap")) return true; if (f.getName().equalsIgnoreCase("hiddenOnForm")) return true; if (f.getName().equalsIgnoreCase("existence")) return true; if (f.getName().equalsIgnoreCase("existence")) { System.out.println(" ==> " + f.getDeclaredClass().getCanonicalName()); } // System.out.println(f.getDeclaredClass()); // return (f.getName().equalsIgnoreCase("code") && f.getDeclaredClass().equals(ArchetypeTerm.class)); //return (f.getName().equalsIgnoreCase("code")); //TODO: check that no other fields named "code" are there return false; } }).registerTypeAdapter(CodePhrase.class, new CodePhraseConverter()) .registerTypeAdapter(DvDateTime.class, new DvDateTimeConverter()) .registerTypeAdapter(Interval.class, new IntervalConverterSequenceFormat()) //.setDateFormat("yyyy-MM-dd'T'HH:mm:ss") // TODO: Check what to do with timezones (probably yoda stuff if DvDateTimeConverter does not suffice) .create(); DumperOptions dumperOptions = new DumperOptions(); //dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK); //dumperOptions.setLineBreak(LineBreak.WIN); dumperOptions.setWidth(120); //dumperOptions.setDefaultFlowStyle(FlowStyle.FLOW); //dumperOptions.setPrettyFlow(true); //dumperOptions.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED); yaml = new Yaml(dumperOptions); // Yaml(new SyntaxSugarRepresenter()); //yaml.setBeanAccess(BeanAccess.PROPERTY); }