net.dongliu.gson.GsonJava8TypeAdapterFactory Java Examples

The following examples show how to use net.dongliu.gson.GsonJava8TypeAdapterFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AboutDialog.java    From BlockMap with MIT License 6 votes vote down vote up
public AboutDialog() throws IOException {
	super(AlertType.NONE, null, ButtonType.CLOSE);
	setTitle("About BlockMap");
	setResizable(true);
	initModality(Modality.APPLICATION_MODAL);

	FXMLLoader loader = new FXMLLoader(getClass().getResource("aboutpane.fxml"));
	loader.setController(this);
	getDialogPane().setContent(loader.load());
	getDialogPane().getStylesheets().add("/de/piegames/blockmap/gui/standalone/about/style.css");

	aboutTitle.setText("BlockMap " + VersionProvider.VERSION);

	@SuppressWarnings("serial")
	List<Dependency> dependencies = new GsonBuilder().registerTypeAdapterFactory(new GsonJava8TypeAdapterFactory()).create().fromJson(
			// TODO automate copying that file on dependency change
			new InputStreamReader(getClass().getResourceAsStream("licenseReport.json")),
			new TypeToken<List<Dependency>>() {
			}.getType());

	for (Dependency dependency : dependencies) {
		this.dependencies.getChildren().add(new DependencyPane(dependency));
	}

	license.setText(LICENSE_TEXT);
}
 
Example #2
Source File: JsonHelperGson.java    From symbol-sdk-java with Apache License 2.0 6 votes vote down vote up
public static final Gson creatGson(boolean pretty) {
    JSON json = new JSON();
    DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
    SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
    ByteArrayAdapter byteArrayAdapter = json.new ByteArrayAdapter();
    GsonBuilder builder = JSON.createGson().registerTypeHierarchyAdapter(
        Collection.class, new CollectionAdapter())
        .registerTypeAdapter(LinkedTreeMap.class, new SortedJsonSerializer())
        .registerTypeAdapter(BigInteger.class, new BigIntegerJsonSerializer())
        .registerTypeAdapter(Double.class, new DoubleJsonSerializer())
        .registerTypeAdapter(Date.class, dateTypeAdapter)
        .registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
        .registerTypeAdapter(byte[].class, byteArrayAdapter)
        .registerTypeAdapterFactory(new GsonJava8TypeAdapterFactory());
    if (pretty) {
        builder.setPrettyPrinting();
    }
    return builder.create();
}
 
Example #3
Source File: GsonValueMapperFactory.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
private GsonBuilder initBuilder(Map<Class, List<Class<?>>> concreteSubTypes, GlobalEnvironment environment) {
    GsonBuilder gsonBuilder = (prototype != null ? prototype.newBuilder() : new GsonBuilder())
            .serializeNulls()
            .setFieldNamingStrategy(fieldNamingStrategy != null ? fieldNamingStrategy : new GsonFieldNamingStrategy(environment.messageBundle))
            .registerTypeAdapterFactory(new GsonJava8TypeAdapterFactory());
    return configurers.stream().reduce(gsonBuilder, (builder, config) ->
                    config.configure(new ConfigurerParams(builder, concreteSubTypes, this.typeInfoGenerator, environment)), (b1, b2) -> b2);
}