List of usage examples for com.google.gson GsonBuilder registerTypeAdapter
@SuppressWarnings({ "unchecked", "rawtypes" }) public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter)
From source file:com.nokia.mole.MoleWS.java
License:Open Source License
public MoleWS() throws IOException { useDynamo = true;//from w w w. ja v a 2 s . co m if (useDynamo) { db = new DynamoDB(CACHE_DYNAMO_PERIOD); } else { db = MemoryDB.loadDB(); } GsonBuilder gBuilder = new GsonBuilder(); gBuilder.registerTypeAdapter(Mac.class, new Mac().new MacDeserializer()).create(); gson = gBuilder.create(); log.info("Started MoleWS " + "version=" + version); }
From source file:com.nuevebit.miroculus.mrna.rest.util.gson.MiRNAGsonConverter.java
private GsonBuilder configureBuilder(GsonBuilder builder) { builder.addDeserializationExclusionStrategy(exclusionStrat); builder.addSerializationExclusionStrategy(exclusionStrat); builder.registerTypeAdapter(Author.class, new JsonSerializer<Author>() { @Override/*from ww w . ja v a 2 s .com*/ public JsonElement serialize(Author src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src.getName()); } }); return builder; }
From source file:com.offbynull.actors.gateways.servlet.JsonConverter.java
License:Open Source License
JsonConverter() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Message.class, new MessageJsonDeserializer()); gsonBuilder.registerTypeAdapter(Message.class, new MessageJsonSerializer()); gsonBuilder.registerTypeAdapter(RequestBlock.class, new RequestBlockDeserializer()); gsonBuilder.registerTypeAdapter(ResponseBlock.class, new ResponseBlockSerializer()); gson = gsonBuilder.create();/*from www. j av a 2 s .c om*/ }
From source file:com.oneops.antenna.senders.generic.HTTPMsgService.java
License:Apache License
@PostConstruct public void init() { // Meter to measure the rate of messages. http = metrics.meter(name(ANTENNA, "http.count")); httpErr = metrics.meter(name(ANTENNA, "http.error")); hpom = metrics.meter(name(ANTENNA, "hpom.count")); hpomErr = metrics.meter(name(ANTENNA, "hpom.error")); GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (date, typeOfSrc, context) -> new JsonPrimitive(date.getTime())); gson = builder.create();/*from www.j a v a 2 s .c o m*/ }
From source file:com.orange.homenap.localmanager.architecturereader.ArchitectureReader.java
License:Open Source License
private List<Component> getComponentsFromArchitecture(String fileStr, List<String> strList) { List<Component> components = new ArrayList<Component>(); //Gson gson = new Gson(); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Constraint.class, new ConstraintAdapter()); Gson gson = gsonBuilder.create();//from ww w . j a v a 2 s . c o m File file = new File(fileStr); String absolutePath = file.getAbsolutePath().replace(file.getName(), ""); for (String str : strList) { StringBuilder json = new StringBuilder(); try { BufferedReader reader = new BufferedReader(new FileReader(absolutePath + str + ".json")); String strLine; while ((strLine = reader.readLine()) != null) json.append(strLine); reader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Component component = null; try { component = gson.fromJson(json.toString(), Component.class); } catch (JsonSyntaxException e) { System.out.println(json.toString()); e.printStackTrace(); } /* System.out.println("-> " + component.getName() + " (" + component.getConstraints().size() + " constraints)"); for(int i = 0; i < component.getConstraints().size(); i++) System.out.println(component.getConstraints().get(i).getName() + ": " + component.getConstraints().get(i).getValue());*/ String url = repositoryManagerItf.addBundleToRepository(component.getUrl()); component.setUrl(url); components.add(component); } return components; }
From source file:com.orange.homenap.localmanager.upnpdevicemanager.LMDevice.java
License:Open Source License
public void actionsToTake(String actions) throws Exception { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter((new TypeToken<List<Action>>() { }).getType(), new ActionListAdapter()); Gson gson = gsonBuilder.create();/*from w w w . java 2 s .c om*/ List<Action> actionList = gson.fromJson(actions, (new TypeToken<List<Action>>() { }).getType()); System.out.println("Receiving " + actionList.size() + " actions to take"); actionsEvent.actionsToTake(actionList); }
From source file:com.paranoid.gerrit.tasks.Deserializers.java
License:Apache License
public static void addDeserializers(GsonBuilder gsonBuilder) { gsonBuilder.registerTypeAdapter(Projects.class, new Projects()); gsonBuilder.registerTypeAdapter(Reviewer.class, d_reviewer); gsonBuilder.registerTypeAdapter(ReviewerList.class, d_reviewers); gsonBuilder.registerTypeAdapter(JSONCommit.class, d_commit); }
From source file:com.paysafe.PaysafeApiClient.java
License:Open Source License
/** * Take a domain object, and json serialize it. * * @param request the request/*from www .j a v a 2s .co m*/ * @param returnType the return type * @return json encoding of the request object */ private String serializeObject(Request request, Class<?> returnType) { final GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.excludeFieldsWithoutExposeAnnotation(); gsonBuilder.registerTypeHierarchyAdapter(AddressContainer.class, new AddressContainerAdapter()); gsonBuilder.registerTypeHierarchyAdapter(Id.class, new IdAdapter()); if (null != request.getSerializer()) { gsonBuilder.registerTypeAdapter(returnType, request.getSerializer()); } final Gson gson = gsonBuilder.create(); return gson.toJson(request.getBody()); }
From source file:com.perl5.lang.perl.idea.run.debugger.PerlDebugThread.java
License:Apache License
protected Gson createGson() { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(PerlDebuggingEvent.class, new PerlDebuggingEventsDeserializer(this)); return builder.excludeFieldsWithModifiers(Modifier.TRANSIENT).create(); }
From source file:com.pkuhelper.model.base.ModelBaseProviderModule.java
License:Open Source License
@Singleton @Provides/*www. j a v a 2 s. co m*/ Gson provideGson(final GsonConfig config) { final GsonBuilder builder = new GsonBuilder(); if (config.autoGsonTypeAdapterFactory() != null) { builder.registerTypeAdapterFactory(config.autoGsonTypeAdapterFactory()); } if (config.fieldNamingPolicy() != null) { builder.setFieldNamingPolicy(config.fieldNamingPolicy()); } return builder .registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeJsonConverter(config.dateTimeFormatter())) .setDateFormat(config.dateFormatString()).setPrettyPrinting().create(); }