Java Code Examples for io.gsonfire.GsonFireBuilder

The following examples show how to use io.gsonfire.GsonFireBuilder. These examples are extracted from open source projects. 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 Project: swaggy-jenkins   Source File: JSON.java    License: MIT License 5 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    
    ;
    GsonBuilder builder = fireBuilder.createGsonBuilder();
    return builder;
}
 
Example 2
Source Project: swagger-aem   Source File: JSON.java    License: Apache License 2.0 5 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    
    ;
    GsonBuilder builder = fireBuilder.createGsonBuilder();
    return builder;
}
 
Example 3
Source Project: huaweicloud-cs-sdk   Source File: JSON.java    License: Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}
 
Example 4
Source Project: huaweicloud-cs-sdk   Source File: JSON.java    License: Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}
 
Example 5
Source Project: android   Source File: JSON.java    License: MIT License 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}
 
Example 6
@Provides
@ActivityScope
Gson providesGson() {
    // configure gson to detect and set proper types
    GsonFireBuilder builder = new GsonFireBuilder()
            .registerPreProcessor(BaseResponse.class, (clazz, src, gson) -> {
                // figure out the response type based on what fields are in the response
                if (src.isJsonObject() && src.getAsJsonObject().get("messageType") == null) {
                    if (src.getAsJsonObject().get("uuid") != null ||
                            (src.getAsJsonObject().get("frontier") != null &&
                                    src.getAsJsonObject().get("representative_block") != null) ||
                            (src.getAsJsonObject().get("error") != null &&
                                    src.getAsJsonObject().get("currency") != null)) {
                        // subscribe response
                        src.getAsJsonObject().addProperty("messageType", Actions.SUBSCRIBE.toString());
                    } else if (src.getAsJsonObject().get("history") != null) {
                        // history response
                        src.getAsJsonObject().addProperty("messageType", Actions.HISTORY.toString());
                        // if history is an empty string, make it an array instead
                        if (!src.getAsJsonObject().get("history").isJsonArray()) {
                            src.getAsJsonObject().add("history", new JsonArray());
                        }
                    } else if (src.getAsJsonObject().get("currency") != null) {
                        // current price
                        src.getAsJsonObject().addProperty("messageType", Actions.PRICE.toString());
                    } else if (src.getAsJsonObject().get("work") != null) {
                        // work response
                        src.getAsJsonObject().addProperty("messageType", Actions.WORK.toString());
                    } else if (src.getAsJsonObject().get("error") != null) {
                        // error response
                        src.getAsJsonObject().addProperty("messageType", Actions.ERROR.toString());
                    } else if (src.getAsJsonObject().get("warning") != null) {
                        // warning response
                        src.getAsJsonObject().addProperty("messageType", Actions.WARNING.toString());
                    } else if (src.getAsJsonObject().get("block") != null && src.getAsJsonObject().get("account") != null
                            && src.getAsJsonObject().get("hash") != null) {
                        // block response
                        src.getAsJsonObject().addProperty("messageType", "block");
                    } else if (src.getAsJsonObject().get("ready") != null) {
                        // account check response
                        src.getAsJsonObject().addProperty("messageType", Actions.CHECK.toString());
                    } else if (src.getAsJsonObject().get("hash") != null) {
                        // process block response
                        src.getAsJsonObject().addProperty("messageType", Actions.PROCESS.toString());
                    } else if (src.getAsJsonObject().get("type") != null &&
                            src.getAsJsonObject().get("type").getAsString().equals(BlockTypes.STATE.toString())) {
                        // state block response
                        src.getAsJsonObject().addProperty("messageType", Actions.PROCESS.toString());
                    } else if (src.getAsJsonObject().get("blocks") != null) {
                        JsonElement blocksElement = src.getAsJsonObject().get("blocks");
                        if (blocksElement.isJsonObject()) {
                            JsonObject blocks = blocksElement.getAsJsonObject();
                            String key = blocks.keySet().iterator().next();
                            if (key != null) {
                                if (blocks.get(key).getAsJsonObject().has("block_account")) {
                                    // get blocks info response
                                    src.getAsJsonObject().addProperty("messageType", Actions.GET_BLOCKS_INFO.toString());
                                }
                            }
                        }
                    }
                }
            }).registerTypeSelector(BaseResponse.class, readElement -> {
                // return proper type based on the message type that was set
                if (readElement.isJsonObject() && readElement.getAsJsonObject().get("messageType") != null) {
                    String kind = readElement.getAsJsonObject().get("messageType").getAsString();
                    if (kind.equals(Actions.SUBSCRIBE.toString())) {
                        return SubscribeResponse.class;
                    } else if (kind.equals(Actions.HISTORY.toString())) {
                        return AccountHistoryResponse.class;
                    } else if (kind.equals(Actions.PRICE.toString())) {
                        return CurrentPriceResponse.class;
                    } else if (kind.equals(Actions.WORK.toString())) {
                        return WorkResponse.class;
                    } else if (kind.equals(Actions.ERROR.toString())) {
                        return ErrorResponse.class;
                    } else if (kind.equals(Actions.WARNING.toString())) {
                        return WarningResponse.class;
                    } else if (kind.equals(Actions.CHECK.toString())) {
                        return AccountCheckResponse.class;
                    } else if (kind.equals(Actions.PROCESS.toString())) {
                        return ProcessResponse.class;
                    } else if (kind.equals(Actions.GET_BLOCKS_INFO.toString())) {
                        return BlocksInfoResponse.class;
                    } else if (kind.equals("block")) {
                        return TransactionResponse.class;
                    } else if (kind.equals("contents")) {
                        return BlockResponse.class;
                    } else {
                        return null; // returning null will trigger Gson's default behavior
                    }
                } else {
                    return null;
                }
            });

    return builder.createGson();
}
 
Example 7
Source Project: java   Source File: JSON.java    License: Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    GsonBuilder builder = fireBuilder.createGsonBuilder();
    return builder;
}
 
Example 8
public static Gson getGson() {
    return new GsonFireBuilder().enableExposeMethodResult().createGsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
}
 
Example 9
Source Project: nifi-swagger-client   Source File: JSON.java    License: Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    GsonBuilder builder = fireBuilder.createGsonBuilder();
    return builder;
}
 
Example 10
Source Project: eve-esi   Source File: JSON.java    License: Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder();
    GsonBuilder builder = fireBuilder.createGsonBuilder();
    return builder;
}
 
Example 11
Source Project: director-sdk   Source File: JSON.java    License: Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}
 
Example 12
Source Project: oxd   Source File: JSON.java    License: Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}