Example usage for com.google.gson.stream JsonReader endObject

List of usage examples for com.google.gson.stream JsonReader endObject

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader endObject.

Prototype

public void endObject() throws IOException 

Source Link

Document

Consumes the next token from the JSON stream and asserts that it is the end of the current object.

Usage

From source file:com.dangdang.ddframe.job.api.config.impl.AbstractJobConfigurationGsonTypeAdapter.java

License:Apache License

private JobEventConfiguration[] getJobEventConfigs(final JsonReader in) throws IOException {
    List<JobEventConfiguration> result = new ArrayList<>(2);
    in.beginObject();//  w  w  w .  j  a  v  a  2  s  .c  o  m
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
        case "log":
            in.beginObject();
            result.add(new JobLogEventConfiguration());
            in.endObject();
            break;
        case "rdb":
            String url = "";
            String username = "";
            String password = "";
            String driverClassName = "";
            String logLevel = "";
            in.beginObject();
            while (in.hasNext()) {
                switch (in.nextName()) {
                case "url":
                    url = in.nextString();
                    break;
                case "username":
                    username = in.nextString();
                    break;
                case "password":
                    password = in.nextString();
                    break;
                case "driverClassName":
                    driverClassName = in.nextString();
                    break;
                case "logLevel":
                    logLevel = in.nextString();
                    break;
                default:
                    break;
                }
            }
            in.endObject();
            result.add(new JobRdbEventConfiguration(driverClassName, url, username, password,
                    LogLevel.valueOf(logLevel.toUpperCase())));
            break;
        default:
            break;
        }
    }
    in.endObject();
    return Iterables.toArray(result, JobEventConfiguration.class);
}

From source file:com.dangdang.ddframe.job.util.AbstractJobConfigurationGsonTypeAdapter.java

License:Apache License

@Override
public T read(final JsonReader in) throws IOException {
    String jobName = "";
    String cron = "";
    int shardingTotalCount = 0;
    String shardingItemParameters = "";
    String jobParameter = "";
    boolean failover = false;
    boolean misfire = failover;
    String description = "";
    JobProperties jobProperties = new JobProperties();
    JobEventConfiguration[] jobEventConfigs = null;
    JobType jobType = null;//from w ww. j a v  a2s  .c om
    String jobClass = "";
    boolean streamingProcess = false;
    String scriptCommandLine = "";
    Map<String, Object> customizedValueMap = new HashMap<>(32, 1);
    in.beginObject();
    while (in.hasNext()) {
        String jsonName = in.nextName();
        switch (jsonName) {
        case "jobName":
            jobName = in.nextString();
            break;
        case "cron":
            cron = in.nextString();
            break;
        case "shardingTotalCount":
            shardingTotalCount = in.nextInt();
            break;
        case "shardingItemParameters":
            shardingItemParameters = in.nextString();
            break;
        case "jobParameter":
            jobParameter = in.nextString();
            break;
        case "failover":
            failover = in.nextBoolean();
            break;
        case "misfire":
            misfire = in.nextBoolean();
            break;
        case "description":
            description = in.nextString();
            break;
        case "jobProperties":
            jobProperties = getJobProperties(in);
            break;
        case "jobEventConfigs":
            jobEventConfigs = getJobEventConfigs(in);
            break;
        case "jobType":
            jobType = JobType.valueOf(in.nextString());
            break;
        case "jobClass":
            jobClass = in.nextString();
            break;
        case "streamingProcess":
            streamingProcess = in.nextBoolean();
            break;
        case "scriptCommandLine":
            scriptCommandLine = in.nextString();
            break;
        default:
            addToCustomizedValueMap(jsonName, in, customizedValueMap);
            break;
        }
    }
    in.endObject();
    JobCoreConfiguration coreConfig = getJobCoreConfiguration(jobName, cron, shardingTotalCount,
            shardingItemParameters, jobParameter, failover, misfire, description, jobProperties,
            jobEventConfigs);
    JobTypeConfiguration typeConfig = getJobTypeConfiguration(coreConfig, jobType, jobClass, streamingProcess,
            scriptCommandLine);
    return getJobRootConfiguration(typeConfig, customizedValueMap);
}

From source file:com.dangdang.ddframe.job.util.AbstractJobConfigurationGsonTypeAdapter.java

License:Apache License

private JobEventConfiguration[] getJobEventConfigs(final JsonReader in) throws IOException {
    List<JobEventConfiguration> result = new ArrayList<>(2);
    in.beginObject();/*from ww w. j  a  va  2s  .co m*/
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
        case "log":
            in.beginObject();
            result.add(new JobEventLogConfiguration());
            in.endObject();
            break;
        case "rdb":
            String url = "";
            String username = "";
            String password = "";
            String driverClassName = "";
            String logLevel = "";
            in.beginObject();
            while (in.hasNext()) {
                switch (in.nextName()) {
                case "url":
                    url = in.nextString();
                    break;
                case "username":
                    username = in.nextString();
                    break;
                case "password":
                    password = in.nextString();
                    break;
                case "driverClassName":
                    driverClassName = in.nextString();
                    break;
                case "logLevel":
                    logLevel = in.nextString();
                    break;
                default:
                    break;
                }
            }
            in.endObject();
            result.add(new JobEventRdbConfiguration(driverClassName, url, username, password,
                    LogLevel.valueOf(logLevel.toUpperCase())));
            break;
        default:
            break;
        }
    }
    in.endObject();
    return Iterables.toArray(result, JobEventConfiguration.class);
}

From source file:com.dangdang.ddframe.job.util.json.AbstractJobConfigurationGsonTypeAdapter.java

License:Apache License

@Override
public T read(final JsonReader in) throws IOException {
    String jobName = "";
    String cron = "";
    int shardingTotalCount = 0;
    String shardingItemParameters = "";
    String jobParameter = "";
    boolean failover = false;
    boolean misfire = failover;
    String description = "";
    JobProperties jobProperties = new JobProperties();
    JobType jobType = null;/*from  ww  w .  j  a  v a 2s .  c  o m*/
    String jobClass = "";
    boolean streamingProcess = false;
    String scriptCommandLine = "";
    Map<String, Object> customizedValueMap = new HashMap<>(32, 1);
    in.beginObject();
    while (in.hasNext()) {
        String jsonName = in.nextName();
        switch (jsonName) {
        case "jobName":
            jobName = in.nextString();
            break;
        case "cron":
            cron = in.nextString();
            break;
        case "shardingTotalCount":
            shardingTotalCount = in.nextInt();
            break;
        case "shardingItemParameters":
            shardingItemParameters = in.nextString();
            break;
        case "jobParameter":
            jobParameter = in.nextString();
            break;
        case "failover":
            failover = in.nextBoolean();
            break;
        case "misfire":
            misfire = in.nextBoolean();
            break;
        case "description":
            description = in.nextString();
            break;
        case "jobProperties":
            jobProperties = getJobProperties(in);
            break;
        case "jobType":
            jobType = JobType.valueOf(in.nextString());
            break;
        case "jobClass":
            jobClass = in.nextString();
            break;
        case "streamingProcess":
            streamingProcess = in.nextBoolean();
            break;
        case "scriptCommandLine":
            scriptCommandLine = in.nextString();
            break;
        default:
            addToCustomizedValueMap(jsonName, in, customizedValueMap);
            break;
        }
    }
    in.endObject();
    JobCoreConfiguration coreConfig = getJobCoreConfiguration(jobName, cron, shardingTotalCount,
            shardingItemParameters, jobParameter, failover, misfire, description, jobProperties);
    JobTypeConfiguration typeConfig = getJobTypeConfiguration(coreConfig, jobType, jobClass, streamingProcess,
            scriptCommandLine);
    return getJobRootConfiguration(typeConfig, customizedValueMap);
}

From source file:com.dracade.ember.core.adapters.ClassAdapter.java

License:Open Source License

@Override
public Class read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        return null;
    }/*  w w w . java  2  s  .co m*/
    in.beginObject();
    in.nextName();
    in.nextString();
    in.nextName();

    Class c = null;
    try {
        c = Class.forName(in.nextString());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    in.endObject();

    return c;
}

From source file:com.dracade.ember.core.adapters.WorldAdapter.java

License:Open Source License

@Override
public World read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        return null;
    }//  w w  w.  j  a va  2s.c  o m

    in.beginObject();
    in.nextName();
    in.nextString();
    in.nextName();

    Optional<World> optional = Ember.game().getServer().getWorld(UUID.fromString(in.nextString()));

    in.endObject();

    return optional.isPresent() ? optional.get() : null;
}

From source file:com.ecwid.mailchimp.internal.gson.MailChimpObjectTypeAdapter.java

License:Apache License

@Override
public MailChimpObject read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();//from  w  ww  .j ava2  s  . com
        return null;
    }

    MailChimpObject result;
    try {
        result = constructor.newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Failed to invoke " + constructor + " with no args", e);
    }

    in.beginObject();
    while (in.hasNext()) {
        final String key;
        if (in.peek() == JsonToken.NAME) {
            key = in.nextName();
        } else {
            key = in.nextString();
        }

        final Object value;

        Type valueType = result.getReflectiveMappingTypes().get(key);
        if (valueType != null) {
            value = gson.getAdapter(TypeToken.get(valueType)).read(in);
        } else {
            if (in.peek() == JsonToken.BEGIN_OBJECT) {
                value = gson.getAdapter(MailChimpObject.class).read(in);
            } else if (in.peek() == JsonToken.BEGIN_ARRAY) {
                value = readList(in);
            } else {
                value = gson.getAdapter(Object.class).read(in);
            }
        }

        if (result.put(key, value) != null) {
            throw new JsonSyntaxException("duplicate key: " + key);
        }
    }
    in.endObject();

    return result;
}

From source file:com.epickrram.romero.testing.server.web.CompletedJobRunIdentifierTypeAdapter.java

License:Apache License

@Override
public CompletedJobRunIdentifier read(final JsonReader jsonReader) throws IOException {
    jsonReader.beginObject();/*from w  w  w.  j a va2 s . c  om*/
    final CompletedJobRunIdentifier.Builder builder = new CompletedJobRunIdentifier.Builder();
    while (jsonReader.hasNext()) {
        final String name = jsonReader.nextName();
        if ("jobRunIdentifier".equals(name)) {
            builder.jobRunIdentifier(jsonReader.nextString());
        } else if ("startTimestamp".equals(name)) {
            builder.startTimestamp(jsonReader.nextLong());
        }
    }
    jsonReader.endObject();
    return builder.create();
}

From source file:com.facebook.buck.worker.WorkerProcessProtocolZero.java

License:Apache License

private static void receiveHandshake(JsonReader reader, int messageId, Optional<Path> stdErr)
        throws IOException {
    int id = -1;//  www.j a  v  a  2 s.  co m
    String type = "";
    String protocolVersion = "";

    try {
        reader.beginArray();
        reader.beginObject();
        while (reader.hasNext()) {
            String property = reader.nextName();
            if (property.equals("id")) {
                id = reader.nextInt();
            } else if (property.equals("type")) {
                type = reader.nextString();
            } else if (property.equals("protocol_version")) {
                protocolVersion = reader.nextString();
            } else if (property.equals("capabilities")) {
                try {
                    reader.beginArray();
                    reader.endArray();
                } catch (IllegalStateException e) {
                    throw new HumanReadableException(
                            "Expected handshake response's \"capabilities\" to " + "be an empty array.");
                }
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
    } catch (IOException e) {
        throw new HumanReadableException(e, "Error receiving handshake response from external process.\n"
                + "Stderr from external process:\n%s", getStdErrorOutput(stdErr));
    }

    if (id != messageId) {
        throw new HumanReadableException(String.format(
                "Expected handshake response's \"id\" value " + "to be \"%d\", got \"%d\" instead.", messageId,
                id));
    }
    if (!type.equals(TYPE_HANDSHAKE)) {
        throw new HumanReadableException(
                String.format("Expected handshake response's \"type\" " + "to be \"%s\", got \"%s\" instead.",
                        TYPE_HANDSHAKE, type));
    }
    if (!protocolVersion.equals(PROTOCOL_VERSION)) {
        throw new HumanReadableException(String.format(
                "Expected handshake response's " + "\"protocol_version\" to be \"%s\", got \"%s\" instead.",
                PROTOCOL_VERSION, protocolVersion));
    }
}

From source file:com.flipkart.batchdemo.adapter.CustomTagDataAdapter.java

License:Open Source License

@Override
public CustomTagData read(JsonReader reader) throws IOException {
    if (reader.peek() == com.google.gson.stream.JsonToken.NULL) {
        reader.nextNull();//from   w ww  . ja  v a  2s.co m
        return null;
    }
    if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) {
        reader.skipValue();
        return null;
    }
    reader.beginObject();

    Tag tag = null;
    Long eventId = 0L;
    JSONObject event = null;
    while (reader.hasNext()) {
        String name = reader.nextName();
        com.google.gson.stream.JsonToken jsonToken = reader.peek();
        if (jsonToken == com.google.gson.stream.JsonToken.NULL) {
            reader.skipValue();
            continue;
        }
        switch (name) {
        case "tag":
            tag = tagTypeAdapter.read(reader);
            break;
        case "eventId":
            eventId = BatchingTypeAdapters.LONG.read(reader);
            break;
        case "event":
            event = BatchingTypeAdapters.getJSONObjectTypeAdapter(gson).read(reader);
            break;
        default:
            reader.skipValue();
            break;
        }
    }

    reader.endObject();
    CustomTagData customTagData = new CustomTagData(tag, event);
    customTagData.setEventId(eventId);
    return customTagData;
}