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

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

Introduction

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

Prototype

public void beginObject() throws IOException 

Source Link

Document

Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.

Usage

From source file:com.confighub.core.utils.Utils.java

License:Open Source License

private static void skipToken(final JsonReader reader) throws IOException {
    final JsonToken token = reader.peek();
    switch (token) {
    case BEGIN_ARRAY:
        reader.beginArray();/*from w w w .j  a v a 2 s . co m*/
        break;
    case END_ARRAY:
        reader.endArray();
        break;
    case BEGIN_OBJECT:
        reader.beginObject();
        break;
    case END_OBJECT:
        reader.endObject();
        break;
    case NAME:
        reader.nextName();
        break;
    case STRING:
    case NUMBER:
    case BOOLEAN:
    case NULL:
        reader.skipValue();
        break;
    case END_DOCUMENT:
    default:
        throw new AssertionError(token);
    }
}

From source file:com.dangdang.ddframe.job.api.config.impl.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;/* w ww  .j  a v a  2  s.co m*/
    String jobClass = "";
    DataflowJobConfiguration.DataflowType dataflowType = null;
    boolean streamingProcess = false;
    int concurrentDataProcessThreadCount = 0;
    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 "dataflowType":
            dataflowType = DataflowJobConfiguration.DataflowType.valueOf(in.nextString());
            break;
        case "streamingProcess":
            streamingProcess = in.nextBoolean();
            break;
        case "concurrentDataProcessThreadCount":
            concurrentDataProcessThreadCount = in.nextInt();
            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, dataflowType,
            streamingProcess, concurrentDataProcessThreadCount, scriptCommandLine);
    return getJobRootConfiguration(typeConfig, customizedValueMap);
}

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

License:Apache License

private JobProperties getJobProperties(final JsonReader in) throws IOException {
    JobProperties result = new JobProperties();
    in.beginObject();
    while (in.hasNext()) {
        switch (in.nextName()) {
        case "job_exception_handler":
            result.put(JobProperties.JobPropertiesEnum.JOB_EXCEPTION_HANDLER.getKey(), in.nextString());
            break;
        case "executor_service_handler":
            result.put(JobProperties.JobPropertiesEnum.EXECUTOR_SERVICE_HANDLER.getKey(), in.nextString());
            break;
        default://from   w ww.  j  a  va 2 s .c  o m
            break;
        }
    }
    in.endObject();
    return result;
}

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();
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
        case "log":
            in.beginObject();/*from www.  j a v a 2s  . c o  m*/
            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;// w ww  .j a va  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 "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();
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
        case "log":
            in.beginObject();/*from   w  w w  . ja  v  a 2  s  .  c o m*/
            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;//  w w w .  j ava 2  s.  co  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;
    }/*from w w  w .j  ava2 s. c  om*/
    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;
    }//from ww  w  .jav a2  s .co 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();/*w w  w  .j  a  v a2 s  . co  m*/
        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;
}