Example usage for com.google.gson FieldAttributes getName

List of usage examples for com.google.gson FieldAttributes getName

Introduction

In this page you can find the example usage for com.google.gson FieldAttributes getName.

Prototype

public String getName() 

Source Link

Usage

From source file:com.tsc9526.monalisa.tools.json.MelpJson.java

License:Open Source License

public static GsonBuilder createGsonBuilder() {
    return new GsonBuilder().registerTypeAdapter(Double.class, new JsonSerializer<Double>() {
        public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) {
            if (src == src.longValue()) {
                return new JsonPrimitive(src.longValue());
            }/*  w  w  w  .j a  v  a2s.c om*/
            return new JsonPrimitive(src);
        }
    }).setExclusionStrategies(new ExclusionStrategy() {
        public boolean shouldSkipField(FieldAttributes fa) {
            return fa.getName().startsWith("$");
        }

        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }
    }).setDateFormat(Conversion.DEFAULT_DATETIME_FORMAT);
}

From source file:com.xse.optstack.persconftool.base.persistence.EmfExclusionStrategy.java

License:Open Source License

@Override
public boolean shouldSkipField(final FieldAttributes fieldAttributes) {
    if (fieldAttributes.getName().equalsIgnoreCase("eStorage")) {
        return true;
    } else if (fieldAttributes.getName().equalsIgnoreCase("eFlags")) {
        return true;
    }//from   w  w w . j a va2 s.  c om
    return false;
}

From source file:com.yalin.fidoclient.op.ASMMessageHandler.java

License:Apache License

private static ExclusionStrategy getExclusionStrategy() {
    return new ExclusionStrategy() {
        @Override/*from ww  w .  java 2 s.c  o  m*/
        public boolean shouldSkipField(FieldAttributes f) {
            return f.getName().equals(ASMRequest.authenticatorIndexName);
        }

        @Override
        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }
    };
}

From source file:dtu.ds.warnme.ws.rest.json.gson.exclusionStrategies.PasswordExclusionStrategy.java

License:Open Source License

@Override
public boolean shouldSkipField(FieldAttributes f) {
    return f.getDeclaringClass().equals(clazz) && f.getName().equals(field.getName());
}

From source file:Editor.EstrategiaGuardado.java

@Override
public boolean shouldSkipField(FieldAttributes fa) {
    return fa.getName().equals("mapa") //Para celdas y enemigos
            || fa.getName().equals("juego"); //Para todos
}

From source file:edu.mayo.cts2.framework.core.json.JsonConverter.java

License:Open Source License

/**
 * Builds the gson.//from   w  w w.j a v  a 2 s .co  m
 *
 * @return the gson
 */
protected Gson buildGson() {
    GsonBuilder gson = new GsonBuilder();

    gson.setDateFormat(ISO_DATE_FORMAT);

    gson.setExclusionStrategies(new ExclusionStrategy() {

        @Override
        public boolean shouldSkipField(FieldAttributes f) {
            return f.getName().equals(CHOICE_VALUE);
        }

        @Override
        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }

    });

    gson.registerTypeAdapter(List.class, new EmptyCollectionSerializer());
    gson.registerTypeAdapter(TsAnyType.class, new TsAnyTypeSerializer());
    gson.registerTypeAdapter(Date.class, new DateTypeAdapter());
    gson.registerTypeAdapterFactory(new ChangeableTypeAdapterFactory());
    gson.registerTypeAdapterFactory(new ChangeableResourceTypeAdapterFactory());

    gson.setFieldNamingStrategy(new FieldNamingStrategy() {

        @Override
        public String translateName(Field field) {
            String fieldName = field.getName();

            char[] array = fieldName.toCharArray();

            if (array[0] == '_') {
                array = ArrayUtils.remove(array, 0);
            }

            String name = new String(array);
            if (name.endsWith(LIST_SUFFIX)) {
                name = StringUtils.removeEnd(name, LIST_SUFFIX);
            }

            return name;
        }

    });

    return gson.create();
}

From source file:es.sm2.openppm.utils.json.Exclusion.java

License:Open Source License

public boolean shouldSkipField(FieldAttributes f) {

    boolean exclusion = false;

    if (nameExlusion.isEmpty()) {
        exclusion = typeToSkip.equals(f.getDeclaredClass());
    } else {/*from   w  w w.  j a va2s.c om*/
        exclusion = (typeToSkip.equals(f.getDeclaredClass()) && nameExlusion.contains(f.getName()));
    }
    return exclusion;
}

From source file:fi.vm.sade.organisaatio.business.impl.OrganisaatioTarjonta.java

License:EUPL

private void initGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();

    // Jtetn oid pois sill KoulutusHakutulosV1RDTO sislt kaksi oid kentt
    gsonBuilder.setExclusionStrategies(new ExclusionStrategy() {
        @Override/*from w w  w . ja  va2s.co  m*/
        public boolean shouldSkipField(FieldAttributes fieldAttributes) {
            return "oid".equals(fieldAttributes.getName());
        }

        @Override
        public boolean shouldSkipClass(Class<?> arg0) {
            return false;
        }
    });

    // Rekisteridn adapteri, jolla hoidetaan date tyyppi long arvona
    gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
        @Override
        public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                throws JsonParseException {
            return new Date(json.getAsJsonPrimitive().getAsLong());
        }
    });

    gson = gsonBuilder.create();
}

From source file:fr.gael.dhus.service.UserService.java

License:Open Source License

/**
 * Facility method to easily provide user content with resolved lazy fields
 * to be able to serialize. The method takes care of the possible cycles
 * such as "users->pref->filescanners->collections->users" ...
 * It also removes possible huge product list from collections.
 *
 * @param u the user to resolve.//from www. j  av a  2  s  .  co m
 * @return the resolved user.
 */
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
@Cacheable(value = "json_user", key = "#u")
public User resolveUser(User u) {
    u = userDao.read(u.getUUID());
    Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
        public boolean shouldSkipClass(Class<?> clazz) {
            // Avoid huge number of products in collection
            return clazz == Product.class;
        }

        /**
         * Custom field exclusion goes here
         */
        public boolean shouldSkipField(FieldAttributes f) {
            // Avoid cycles caused by collection tree and user/auth users...
            return f.getName().equals("authorizedUsers") || f.getName().equals("parent")
                    || f.getName().equals("subCollections");

        }
    }).serializeNulls().create();
    String users_string = gson.toJson(u);
    return gson.fromJson(users_string, User.class);
}

From source file:hd3gtv.tools.GsonIgnoreStrategy.java

License:Open Source License

public boolean shouldSkipField(FieldAttributes f) {
    if (DEBUG) {/*from ww w .j av a2s.co m*/
        System.out.println(f.getName());
        System.out.println(f.getAnnotation(GsonIgnore.class));
    }
    return f.getAnnotation(GsonIgnore.class) != null;
}