List of usage examples for com.google.gson GsonBuilder GsonBuilder
public GsonBuilder()
From source file:at.maui.cheapcast.chromecast.SessionSocket.java
License:Apache License
public SessionSocket(CheapCastService service, App app) { mService = service;//ww w .ja va2 s . c o m mApp = app; mContext = service; mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); mGson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(ProtocolMessage.class, new ProtocolMessageDeserializer()) .registerTypeAdapter(ProtocolMessage.class, new ProtocolMessageSerializer()) .registerTypeAdapter(RampMessage.class, new RampMessageDeserializer()) .registerTypeAdapter(CmMessage.class, new CmMessageDeserializer()).create(); }
From source file:at.maui.cheapcast.chromecast.SystemControlSocket.java
License:Apache License
public SystemControlSocket(Context ctx) { mContext = ctx;//from w ww. j a v a2 s . c om mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); mGson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); }
From source file:at.maui.gradle.plugin.imgcat.ImgcatTask.java
License:Open Source License
@TaskAction public void imgcat() { ImgcatExtension extension = getProject().getExtensions().findByType(ImgcatExtension.class); if (extension == null) { extension = new ImgcatExtension(); }//from w w w. j a v a2s . c o m if (extension.getSource().equals(ImgcatExtension.SOURCE_GIPHY)) { try { URL giphyUrl = null; if (extension.getValue() == null) { giphyUrl = new URL(GIPHY_API_BASE_URL); } else { giphyUrl = new URL(GIPHY_API_BASE_URL + "&tag=" + extension.getValue()); } Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); GiphyResponse giphyResponse = gson.fromJson(new String(Utils.fetchUrl(giphyUrl)), GiphyResponse.class); System.out.println(Imgcat.output("giphy.gif", true, Utils.fetchUrl(new URL(giphyResponse.getData().getImageUrl())))); System.out.println("Powered By Giphy (http://www.giphy.com)"); } catch (Exception ex) { System.out.println("Could'nt imgcat random giphy image"); } } else if (extension.getSource().equals(ImgcatExtension.SOURCE_FILE)) { try { File localFile = new File(extension.getValue()); System.out.println(Imgcat.output(localFile.getName(), true, Utils.fetchFile(localFile))); } catch (IOException e) { System.out.println("Could'nt imgcat local file at " + extension.getValue()); } } else if (extension.getSource().equals(ImgcatExtension.SOURCE_REMOTE)) { try { System.out .println(Imgcat.output("remote.gif", true, Utils.fetchUrl(new URL(extension.getValue())))); } catch (IOException e) { System.out.println("Could'nt imgcat remote with URL " + extension.getValue()); } } }
From source file:at.medevit.elexis.emediplan.core.internal.EMediplanServiceImpl.java
License:Open Source License
public EMediplanServiceImpl() { gson = new GsonBuilder().create(); }
From source file:at.medevit.elexis.emediplan.core.internal.EMediplanServiceImpl.java
License:Open Source License
@Override public Medication createModelFromChunk(String chunk) { String json = getDecodedJsonString(chunk); if (chunk.length() > 8) { logger.debug("json version: " + chunk.substring(5, 8)); GsonBuilder gb = new GsonBuilder(); gb.registerTypeAdapter(Medication.class, new MedicationDeserializer()); Gson g = gb.create();// ww w . j a v a 2 s .c om Medication m = g.fromJson(json, Medication.class); m.chunk = chunk; return m; } else { logger.error("invalid json length - cannot parseable"); } return null; }
From source file:at.mukprojects.giphy4j.Giphy.java
License:Open Source License
/** * Constructs a new Giphy object.// w ww . j a v a 2 s . com * * @param apiKey * the GiphyAPI key */ public Giphy(String apiKey) { this.apiKey = apiKey; sender = new HttpRequestSender(); gson = new GsonBuilder().setPrettyPrinting().create(); }
From source file:at.mukprojects.giphy4j.Giphy.java
License:Open Source License
/** * Constructs a new HttpRequestSender object. * // w w w . j a v a 2s . c om * <p> * It's recommended to use the simple constructor without a sender argument. * This one is just for testing purposes or in case you want to use the * sender with different settings. * * @param apiKey * the GiphyAPI key * @param sender * the sender object * */ public Giphy(String apiKey, RequestSender sender) { this.apiKey = apiKey; this.sender = sender; gson = new GsonBuilder().setPrettyPrinting().create(); }
From source file:at.orz.arangodb.entity.EntityFactory.java
License:Apache License
private static GsonBuilder getBuilder() { return new GsonBuilder().addSerializationExclusionStrategy(new ExcludeExclusionStrategy(true)) .addDeserializationExclusionStrategy(new ExcludeExclusionStrategy(false)) .setFieldNamingStrategy(new ArangoFieldNamingStrategy()) .registerTypeAdapter(CollectionStatus.class, new CollectionStatusTypeAdapter()) .registerTypeAdapter(CollectionEntity.class, new EntityDeserializers.CollectionEntityDeserializer()) .registerTypeAdapter(DocumentEntity.class, new EntityDeserializers.DocumentEntityDeserializer()) .registerTypeAdapter(DocumentsEntity.class, new EntityDeserializers.DocumentsEntityDeserializer()) .registerTypeAdapter(ArangoVersion.class, new EntityDeserializers.VersionDeserializer()) .registerTypeAdapter(ArangoUnixTime.class, new EntityDeserializers.ArangoUnixTimeDeserializer()) .registerTypeAdapter(DefaultEntity.class, new EntityDeserializers.DefaultEntityDeserializer()) .registerTypeAdapter(Figures.class, new EntityDeserializers.FiguresDeserializer()) .registerTypeAdapter(CursorEntity.class, new EntityDeserializers.CursorEntityDeserializer()) .registerTypeAdapter(IndexEntity.class, new EntityDeserializers.IndexEntityDeserializer()) .registerTypeAdapter(IndexesEntity.class, new EntityDeserializers.IndexesEntityDeserializer()) .registerTypeAdapter(ScalarExampleEntity.class, new EntityDeserializers.ScalarExampleEntityDeserializer()) .registerTypeAdapter(SimpleByResultEntity.class, new EntityDeserializers.SimpleByResultEntityDeserializer()) .registerTypeAdapter(AdminLogEntity.class, new EntityDeserializers.AdminLogEntryEntityDeserializer()) .registerTypeAdapter(StatisticsEntity.class, new EntityDeserializers.StatisticsEntityDeserializer()) .registerTypeAdapter(StatisticsDescriptionEntity.class, new EntityDeserializers.StatisticsDescriptionEntityDeserializer()) .registerTypeAdapter(ExplainEntity.class, new EntityDeserializers.ExplainEntityDeserializer()) .registerTypeAdapter(UserEntity.class, new EntityDeserializers.UserEntityDeserializer()) .registerTypeAdapter(ImportResultEntity.class, new EntityDeserializers.ImportResultEntityDeserializer()) .registerTypeAdapter(DatabaseEntity.class, new EntityDeserializers.DatabaseEntityDeserializer()) .registerTypeAdapter(StringsResultEntity.class, new EntityDeserializers.StringsResultEntityDeserializer()) .registerTypeAdapter(BooleanResultEntity.class, new EntityDeserializers.BooleanResultEntityDeserializer()) .registerTypeAdapter(Endpoint.class, new EntityDeserializers.EndpointDeserializer()) .registerTypeAdapter(DocumentResultEntity.class, new EntityDeserializers.DocumentResultEntityDeserializer()) .registerTypeAdapter(CollectionKeyOptionDeserializer.class, new EntityDeserializers.CollectionKeyOptionDeserializer()) .registerTypeAdapter(ReplicationInventoryEntity.class, new EntityDeserializers.ReplicationInventoryEntityDeserializer()) .registerTypeAdapter(ReplicationDumpRecord.class, new EntityDeserializers.ReplicationDumpRecordDeserializer()) .registerTypeAdapter(ReplicationSyncEntity.class, new EntityDeserializers.ReplicationSyncEntityDeserializer()) .registerTypeAdapter(MapAsEntity.class, new EntityDeserializers.MapAsEntityDeserializer()) .registerTypeAdapter(ReplicationLoggerConfigEntity.class, new EntityDeserializers.ReplicationLoggerConfigEntityDeserializer()) .registerTypeAdapter(ReplicationApplierConfigEntity.class, new EntityDeserializers.ReplicationApplierConfigEntityDeserializer()) .registerTypeAdapter(ReplicationApplierState.class, new EntityDeserializers.ReplicationApplierStateDeserializer()) .registerTypeAdapter(ReplicationApplierStateEntity.class, new EntityDeserializers.ReplicationApplierStateEntityDeserializer()) .registerTypeAdapter(ReplicationLoggerStateEntity.class, new EntityDeserializers.ReplicationLoggerStateEntityDeserializer()) .registerTypeAdapter(ReplicationLoggerStateEntity.Client.class, new EntityDeserializers.ReplicationLoggerStateEntityClientDeserializer()) .registerTypeAdapter(GraphEntity.class, new EntityDeserializers.GraphEntityDeserializer()) .registerTypeAdapter(GraphsEntity.class, new EntityDeserializers.GraphsEntityDeserializer()) .registerTypeAdapter(DeletedEntity.class, new EntityDeserializers.DeleteEntityDeserializer()) .registerTypeAdapter(VertexEntity.class, new EntityDeserializers.VertexEntityDeserializer()) .registerTypeAdapter(EdgeEntity.class, new EntityDeserializers.EdgeEntityDeserializer()); }
From source file:at.rocworks.oa4j.logger.data.Metrics.java
public String toJSONPrettyString() { return (new GsonBuilder().setPrettyPrinting().create()).toJson(toJSONObject()); }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
public static void main(String[] args) { try {/* w w w . ja v a 2 s .c om*/ ImportExport ie = new ImportExport(args); File io = new File(ie.file); if (ie.export) { BufferedWriter out = new BufferedWriter(new FileWriter(io, false)); Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(ie.export()); out.write(gson.toJson(je)); out.close(); } else { BufferedReader in = new BufferedReader(new FileReader(io)); ie.imPort(new JsonParser().parse(in).getAsJsonObject()); in.close(); } } catch (Exception e) { System.err.println("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } }