All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cognite.client.servicesV1.response.JsonThreeDOutputsParser Maven / Gradle / Ivy

There is a newer version: 2.3.3
Show newest version
package com.cognite.client.servicesV1.response;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;

import java.util.ArrayList;

@AutoValue
public abstract class JsonThreeDOutputsParser extends DefaultResponseParser {

    public static JsonThreeDOutputsParser.Builder builder() {
        return new AutoValue_JsonThreeDOutputsParser.Builder();
    }

    public abstract Builder toBuilder();

    @Override
    public ImmutableList extractItems(String json) throws Exception {
        ArrayList tempList = new ArrayList<>();

        JsonNode node = objectMapper.readTree(json).path("items");
        if (node.isArray()) {
            LOG.debug("Found items array in json response payload.");
            for (JsonNode child : node) {
                if (child.isObject()) {
                    tempList.add(child.toString());
                } else {
                    tempList.add(child.textValue());
                }
            }
            return ImmutableList.copyOf(tempList);
        }
        LOG.info("items array not found in Json payload: \r\n" + json
                .substring(0, Math.min(MAX_LENGTH_JSON_LOG, json.length())));
        return ImmutableList.of();
    }

    @AutoValue.Builder
    public abstract static class Builder {
        public abstract JsonThreeDOutputsParser build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy