io.gsonfire.GsonFireBuilder Java Examples

The following examples show how to use io.gsonfire.GsonFireBuilder. 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: JSON.java    From swaggy-jenkins with 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 File: JSON.java    From swagger-aem with 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 File: JSON.java    From huaweicloud-cs-sdk with Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}
 
Example #4
Source File: JSON.java    From huaweicloud-cs-sdk with Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}
 
Example #5
Source File: JSON.java    From android with MIT License 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}
 
Example #6
Source File: ActivityModule.java    From nano-wallet-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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 File: JSON.java    From java with 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
Source File: SerialisationGsonBuilder.java    From Photato with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Gson getGson() {
    return new GsonFireBuilder().enableExposeMethodResult().createGsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
}
 
Example #9
Source File: JSON.java    From nifi-swagger-client with 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 File: JSON.java    From eve-esi with 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 File: JSON.java    From director-sdk with Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}
 
Example #12
Source File: JSON.java    From oxd with Apache License 2.0 4 votes vote down vote up
public static GsonBuilder createGson() {
    GsonFireBuilder fireBuilder = new GsonFireBuilder()
    ;
    return fireBuilder.createGsonBuilder();
}