Java Code Examples for com.fasterxml.jackson.core.JsonParser#nextTextValue()

The following examples show how to use com.fasterxml.jackson.core.JsonParser#nextTextValue() . 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: MetadataParser.java    From wikireverse with MIT License 6 votes vote down vote up
private static HashSet<String> parseLinks(JsonParser parser, String linkType, String linkFilter) throws JsonParseException, IOException {
	HashSet<String> linkUrls = new HashSet<String>();
	String fieldName = "", pathValue = "", linkHref = "";

	while (parser.nextToken() != JsonToken.END_ARRAY) {
		while (parser.nextToken() != JsonToken.END_OBJECT) {
			fieldName = parser.getCurrentName();

			if (PATH.equals(fieldName)) {
				pathValue = parser.nextTextValue();
			}

			if (URL.equals(fieldName)) {
				linkHref = parser.nextTextValue().trim();

				if (linkType.equals(pathValue) && linkHref.indexOf(linkFilter) >= 0)
					linkUrls.add(linkHref);
			}
		}
	}
	
	return linkUrls;
}
 
Example 2
Source File: JsonDatabaseReader.java    From dbsync with Apache License 2.0 6 votes vote down vote up
private void readTable(JsonParser jp) throws IOException {
    JsonToken token;
    String tableName = "";
    int recordCount = 0;

    while((token = jp.nextToken()) != JsonToken.END_OBJECT) {

        if (token == JsonToken.FIELD_NAME) {
            if ("name".equals(jp.getCurrentName())) {
                tableName = jp.nextTextValue();
            } else if ("records".equals(jp.getCurrentName())){
                // Ciclo la lista dei records
                while((token = jp.nextToken()) != JsonToken.END_ARRAY) {
                    readRecord(jp);
                    recordCount++;
                }
            }
        }
    }
    System.out.println("\tTable: " + tableName + " records:" + recordCount);

    numeriche.put(tableName, recordCount);
}
 
Example 3
Source File: FilterDeserializer.java    From ffwd with Apache License 2.0 6 votes vote down vote up
@Override
public Filter deserialize(JsonParser p, DeserializationContext ctx)
    throws IOException, JsonProcessingException {
    if (p.getCurrentToken() != JsonToken.START_ARRAY) {
        throw ctx.wrongTokenException(p, JsonToken.START_ARRAY, null);
    }

    final String id = p.nextTextValue();

    final PartialDeserializer d = suppliers.get(id);

    if (d == null) {
        throw ctx.weirdStringException(id, Filter.class,
            String.format("Expected one of %s", suppliers.keySet()));
    }

    final Filter instance = d.deserialize(p, ctx);

    if (p.getCurrentToken() != JsonToken.END_ARRAY) {
        throw ctx.wrongTokenException(p, JsonToken.END_ARRAY, null);
    }

    return instance;
}
 
Example 4
Source File: MatchTag.java    From ffwd with Apache License 2.0 5 votes vote down vote up
@Override
public Filter deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
    final String key = p.nextTextValue();
    final String value = p.nextTextValue();

    if (p.nextToken() != JsonToken.END_ARRAY) {
        throw ctx.wrongTokenException(p, JsonToken.END_ARRAY, null);
    }

    return new MatchTag(key, value);
}
 
Example 5
Source File: ClientCsdlIsOf.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
protected ClientCsdlIsOf doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
    throws IOException {
  final ClientCsdlIsOf isof = new ClientCsdlIsOf();
  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Type".equals(jp.getCurrentName())) {
        isof.setType(jp.nextTextValue());
      } else if ("Annotation".equals(jp.getCurrentName())) {
        isof.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class));
      } else if ("MaxLength".equals(jp.getCurrentName())) {
        final String maxLenght = jp.nextTextValue();
        isof.setMaxLength("max".equalsIgnoreCase(maxLenght) ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
      } else if ("Precision".equals(jp.getCurrentName())) {
        isof.setPrecision(Integer.valueOf(jp.nextTextValue()));
      } else if ("Scale".equals(jp.getCurrentName())) {
        final String scale = jp.nextTextValue();
        isof.setScale("variable".equalsIgnoreCase(scale) || "floating".equalsIgnoreCase(scale) ?
            0 : Integer.valueOf(scale));
      } else if ("SRID".equals(jp.getCurrentName())) {
        final String srid = jp.nextTextValue();
        if (srid != null) {
          isof.setSrid(SRID.valueOf(srid));
        }
      } else {
        isof.setValue(jp.readValueAs(ClientCsdlDynamicExpression.class));
      }
    }
  }
  return isof;
}
 
Example 6
Source File: JsonUtilsTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
private Map<Id, Delta> decode(byte[] json) throws IOException {
  Map<Id, Delta> values = new HashMap<>();
  JsonParser parser = FACTORY.createParser(json);

  // Array start
  Assertions.assertEquals(JsonToken.START_ARRAY, parser.nextToken());

  // String table
  String[] strings = new String[parser.nextIntValue(-1)];
  for (int i = 0; i < strings.length; ++i) {
    strings[i] = parser.nextTextValue();
  }

  // Read measurements
  parser.nextToken();
  while (parser.currentToken() != JsonToken.END_ARRAY) {
    int n = parser.getIntValue();
    Map<String, String> tags = new HashMap<>(n);
    for (int i = 0; i < n; ++i) {
      String k = strings[parser.nextIntValue(-1)];
      String v = strings[parser.nextIntValue(-1)];
      tags.put(k, v);
    }
    String name = tags.get("name");
    tags.remove("name");
    Id id = registry.createId(name).withTags(tags);
    int op = parser.nextIntValue(-1);
    parser.nextToken();
    double value = parser.getDoubleValue();
    values.put(id, new Delta(op, value));

    parser.nextToken();
  }

  return values;
}
 
Example 7
Source File: JsonTranscoderTest.java    From simple-spring-memcached with MIT License 5 votes vote down vote up
@Override
public Point deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
    jp.nextToken();
    String value = jp.nextTextValue();
    jp.nextToken();
    String[] parts = value.split("x");
    return new Point(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]));
}
 
Example 8
Source File: XMLServiceDocumentDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getName(final JsonParser jp) throws IOException {
  String title = jp.nextTextValue();
  if (title == null) {
    jp.nextToken();
    jp.nextToken();
    jp.nextToken();
    title = jp.nextTextValue();
  }
  return title;
}
 
Example 9
Source File: ClientCsdlCast.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
protected ClientCsdlCast doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {
  final ClientCsdlCast cast = new ClientCsdlCast();
  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Type".equals(jp.getCurrentName())) {
        cast.setType(jp.nextTextValue());
      } else if ("Annotation".equals(jp.getCurrentName())) {
        cast.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class));
      } else if ("MaxLength".equals(jp.getCurrentName())) {
        final String maxLenght = jp.nextTextValue();
        cast.setMaxLength("max".equalsIgnoreCase(maxLenght) ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
      } else if ("Precision".equals(jp.getCurrentName())) {
        cast.setPrecision(Integer.valueOf(jp.nextTextValue()));
      } else if ("Scale".equals(jp.getCurrentName())) {
        final String scale = jp.nextTextValue();
        cast.setScale("variable".equalsIgnoreCase(scale) || "floating".equalsIgnoreCase(scale) ?
            0 : Integer.valueOf(scale));
      } else if ("SRID".equals(jp.getCurrentName())) {
        final String srid = jp.nextTextValue();
        if (srid != null) {
          cast.setSrid(SRID.valueOf(srid));
        }
      } else {
        cast.setValue(jp.readValueAs(ClientCsdlDynamicExpression.class));
      }
    }
  }
  return cast;
}
 
Example 10
Source File: TimeSeriesMetadata.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
static void parseFieldName(JsonParser parser, JsonParsingContext context) throws IOException {
    String fieldName = parser.getCurrentName();
    if (context.insideTags) {
        context.tags.put(fieldName, parser.nextTextValue());
    } else {
        switch (fieldName) {
            case "metadata":
                break;
            case "name":
                context.name = parser.nextTextValue();
                break;
            case "dataType":
                context.dataType = TimeSeriesDataType.valueOf(parser.nextTextValue());
                break;
            case "tags":
                context.insideTags = true;
                break;
            case RegularTimeSeriesIndex.TYPE:
                context.index = RegularTimeSeriesIndex.parseJson(parser);
                break;
            case IrregularTimeSeriesIndex.TYPE:
                context.index = IrregularTimeSeriesIndex.parseJson(parser);
                break;
            case InfiniteTimeSeriesIndex.TYPE:
                context.index = InfiniteTimeSeriesIndex.parseJson(parser);
                break;
            default:
                throw new IllegalStateException("Unexpected field name " + fieldName);
        }
    }
}
 
Example 11
Source File: EnumReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
@Override
public Object readNext(JSONReader reader, JsonParser p) throws IOException {
    String name = p.nextTextValue();
    if (name != null) {
        return _enum(name);
    }
    return read(reader, p);
}
 
Example 12
Source File: CredentialModule.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public OAuthToken deserialize(final JsonParser p, final DeserializationContext ctxt)
    throws IOException, JsonProcessingException {
    final Map<String, String> values = new HashMap<>();
    String fieldName;
    while ((fieldName = p.nextFieldName()) != null) {
        final String nextValue = p.nextTextValue();
        values.put(fieldName, nextValue);
    }

    return new OAuthToken(values.get("value"), values.get("secret"));
}
 
Example 13
Source File: ContingencyDeserializer.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Contingency deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
    String id = null;
    List<ContingencyElement> elements = Collections.emptyList();

    List<Extension<Contingency>> extensions = Collections.emptyList();

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        switch (parser.getCurrentName()) {
            case "id":
                id = parser.nextTextValue();
                break;

            case "elements":
                parser.nextToken();
                elements = parser.readValueAs(new TypeReference<ArrayList<ContingencyElement>>() {
                });
                break;

            case "extensions":
                parser.nextToken();
                extensions = JsonUtil.readExtensions(parser, deserializationContext, SUPPLIER.get());
                break;

            default:
                throw new AssertionError("Unexpected field: " + parser.getCurrentName());
        }
    }

    Contingency contingency = new Contingency(id, elements);
    SUPPLIER.get().addExtensions(contingency, extensions);

    return contingency;
}
 
Example 14
Source File: ClientCsdlProperty.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
protected ClientCsdlProperty doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

  final ClientCsdlProperty property = new ClientCsdlProperty();

  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Name".equals(jp.getCurrentName())) {
        property.setName(jp.nextTextValue());
      } else if ("Type".equals(jp.getCurrentName())) {
        String metadataTypeName = jp.nextTextValue();
        if (metadataTypeName.startsWith("Collection(")) {
          property.setType(metadataTypeName.substring(metadataTypeName.indexOf("(") + 1,
                  metadataTypeName.length() - 1));
          property.setCollection(true);
        } else {
          property.setType(metadataTypeName);
          property.setCollection(false);
        }
      } else if ("Nullable".equals(jp.getCurrentName())) {
        property.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
      } else if ("DefaultValue".equals(jp.getCurrentName())) {
        property.setDefaultValue(jp.nextTextValue());
      } else if ("MaxLength".equals(jp.getCurrentName())) {
        final String maxLenght = jp.nextTextValue();
        property.setMaxLength("max".equalsIgnoreCase(maxLenght) ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
      } else if ("Precision".equals(jp.getCurrentName())) {
        property.setPrecision(Integer.valueOf(jp.nextTextValue()));
      } else if ("Scale".equals(jp.getCurrentName())) {
        final String scale = jp.nextTextValue();
        property.setScale("variable".equalsIgnoreCase(scale) || "floating".equalsIgnoreCase(scale) ?
            0 : Integer.valueOf(scale));
      } else if ("Unicode".equals(jp.getCurrentName())) {
        property.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue()));
      } else if ("SRID".equals(jp.getCurrentName())) {
        final String srid = jp.nextTextValue();
        if (srid != null) {
          property.setSrid(SRID.valueOf(srid));
        }
      } else if ("Annotation".equals(jp.getCurrentName())) {
        jp.nextToken();
        property.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class));
      }
    }
  }

  return property;
}
 
Example 15
Source File: FilmlisteLesen.java    From MLib with GNU General Public License v3.0 4 votes vote down vote up
private void readData(JsonParser jp, ListeFilme listeFilme) throws IOException {
    JsonToken jsonToken;
    String sender = "", thema = "";

    if (jp.nextToken() != JsonToken.START_OBJECT) {
        throw new IllegalStateException("Expected data to start with an Object");
    }

    while ((jsonToken = jp.nextToken()) != null) {
        if (jsonToken == JsonToken.END_OBJECT) {
            break;
        }
        if (jp.isExpectedStartArrayToken()) {
            for (int k = 0; k < ListeFilme.MAX_ELEM; ++k) {
                listeFilme.metaDaten[k] = jp.nextTextValue();
            }
            break;
        }
    }
    while ((jsonToken = jp.nextToken()) != null) {
        if (jsonToken == JsonToken.END_OBJECT) {
            break;
        }
        if (jp.isExpectedStartArrayToken()) {
            // sind nur die Feldbeschreibungen, brauch mer nicht
            jp.nextToken();
            break;
        }
    }
    while (!Config.getStop() && (jsonToken = jp.nextToken()) != null) {
        if (jsonToken == JsonToken.END_OBJECT) {
            break;
        }
        if (jp.isExpectedStartArrayToken()) {
            DatenFilm datenFilm = new DatenFilm();
            for (int i = 0; i < DatenFilm.JSON_NAMES.length; ++i) {
                //if we are in FASTAUTO mode, we don´t need film descriptions.
                //this should speed up loading on low end devices...
                if (workMode == WorkMode.FASTAUTO) {
                    if (DatenFilm.JSON_NAMES[i] == DatenFilm.FILM_BESCHREIBUNG
                            || DatenFilm.JSON_NAMES[i] == DatenFilm.FILM_WEBSEITE
                            || DatenFilm.JSON_NAMES[i] == DatenFilm.FILM_GEO) {
                        jp.nextToken();
                        continue;
                    }
                }
                if (DatenFilm.JSON_NAMES[i] == DatenFilm.FILM_NEU) {
                    final String value = jp.nextTextValue();
                    //This value is unused...
                    //datenFilm.arr[DatenFilm.FILM_NEU_NR] = value;
                    datenFilm.setNew(Boolean.parseBoolean(value));
                } else {
                    datenFilm.arr[DatenFilm.JSON_NAMES[i]] = jp.nextTextValue();
                }

                /// für die Entwicklungszeit
                if (datenFilm.arr[DatenFilm.JSON_NAMES[i]] == null) {
                    datenFilm.arr[DatenFilm.JSON_NAMES[i]] = "";
                }
            }
            if (datenFilm.arr[DatenFilm.FILM_SENDER].isEmpty()) {
                datenFilm.arr[DatenFilm.FILM_SENDER] = sender;
            } else {
                sender = datenFilm.arr[DatenFilm.FILM_SENDER];
            }
            if (datenFilm.arr[DatenFilm.FILM_THEMA].isEmpty()) {
                datenFilm.arr[DatenFilm.FILM_THEMA] = thema;
            } else {
                thema = datenFilm.arr[DatenFilm.FILM_THEMA];
            }

            listeFilme.importFilmliste(datenFilm);
            if (milliseconds > 0) {
                // muss "rückwärts" laufen, da das Datum sonst 2x gebaut werden muss
                // wenns drin bleibt, kann mans noch ändern
                if (!checkDate(datenFilm)) {
                    listeFilme.remove(datenFilm);
                }
            }
        }
    }
}
 
Example 16
Source File: LimitViolationDeserializer.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public LimitViolation deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
    String subjectId = null;
    String subjectName = null;
    LimitViolationType limitType = null;
    String limitName = null;
    int acceptableDuration = Integer.MAX_VALUE;
    double limit = Double.NaN;
    float limitReduction = Float.NaN;
    double value = Double.NaN;
    Branch.Side side = null;

    List<Extension<LimitViolation>> extensions = Collections.emptyList();

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        switch (parser.getCurrentName()) {
            case "subjectId":
                subjectId = parser.nextTextValue();
                break;

            case "subjectName":
                subjectName = parser.nextTextValue();
                break;

            case "limitType":
                parser.nextToken();
                limitType = parser.readValueAs(LimitViolationType.class);
                break;

            case "limitName":
                limitName = parser.nextTextValue();
                break;

            case "acceptableDuration":
                parser.nextToken();
                acceptableDuration = parser.readValueAs(Integer.class);
                break;

            case "limit":
                parser.nextToken();
                limit = parser.readValueAs(Double.class);
                break;

            case "limitReduction":
                parser.nextToken();
                limitReduction = parser.readValueAs(Float.class);
                break;

            case "value":
                parser.nextToken();
                value = parser.readValueAs(Double.class);
                break;

            case "side":
                parser.nextToken();
                side = parser.readValueAs(Branch.Side.class);
                break;

            case "extensions":
                parser.nextToken();
                extensions = JsonUtil.readExtensions(parser, deserializationContext, SUPPLIER.get());
                break;

            default:
                throw new AssertionError("Unexpected field: " + parser.getCurrentName());
        }
    }

    LimitViolation violation = new LimitViolation(subjectId, subjectName, limitType, limitName, acceptableDuration, limit, limitReduction, value, side);
    SUPPLIER.get().addExtensions(violation, extensions);

    return violation;
}
 
Example 17
Source File: NetworkMetadataDeserializer.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public NetworkMetadata deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
    String id = null;
    String sourceFormat = null;
    DateTime caseDate = null;
    int forecastDistance = 0;

    List<Extension<NetworkMetadata>> extensions = Collections.emptyList();

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        switch (parser.getCurrentName()) {
            case "id":
                id = parser.nextTextValue();
                break;

            case "sourceFormat":
                sourceFormat = parser.nextTextValue();
                break;

            case "caseDate":
                caseDate = DateTime.parse(parser.nextTextValue());
                break;

            case "forecastDistance":
                forecastDistance = parser.nextIntValue(0);
                break;

            case "extensions":
                parser.nextToken();
                extensions = JsonUtil.readExtensions(parser, deserializationContext, SUPPLIER.get());
                break;

            default:
                throw new PowsyblException("Unexpected field: " + parser.getCurrentName());
        }
    }

    NetworkMetadata metadata = new NetworkMetadata(id, sourceFormat, caseDate, forecastDistance);
    SUPPLIER.get().addExtensions(metadata, extensions);

    return metadata;
}
 
Example 18
Source File: ClientCsdlReturnType.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
protected ClientCsdlReturnType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {
  final ClientCsdlReturnType returnType = new ClientCsdlReturnType();

  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Type".equals(jp.getCurrentName())) {
        String metadataTypeName = jp.nextTextValue();
        if (metadataTypeName.startsWith("Collection(")) {
          returnType.setType(metadataTypeName.substring(metadataTypeName.indexOf("(") + 1,
                  metadataTypeName.length() - 1));
          returnType.setCollection(true);
        } else {
          returnType.setType(metadataTypeName);
          returnType.setCollection(false);
        }
      } else if ("Nullable".equals(jp.getCurrentName())) {
        returnType.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
      } else if ("MaxLength".equals(jp.getCurrentName())) {
        final String maxLenght = jp.nextTextValue();
        returnType.setMaxLength("max".equalsIgnoreCase(maxLenght) ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
      } else if ("Precision".equals(jp.getCurrentName())) {
        returnType.setPrecision(Integer.valueOf(jp.nextTextValue()));
      } else if ("Scale".equals(jp.getCurrentName())) {
        final String scale = jp.nextTextValue();
        returnType.setScale("variable".equalsIgnoreCase(scale) || "floating".equalsIgnoreCase(scale) ?
            0 : Integer.valueOf(scale));
      } else if ("SRID".equals(jp.getCurrentName())) {
        final String srid = jp.nextTextValue();
        if (srid != null) {
          returnType.setSrid(SRID.valueOf(srid));
        }
      } else if ("Annotation".equals(jp.getCurrentName())) {
        jp.nextToken();
        returnType.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class));
      }
    }
  }

  return returnType;
}
 
Example 19
Source File: ClientCsdlTerm.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
protected ClientCsdlTerm doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {
  final ClientCsdlTerm term = new ClientCsdlTerm();

  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Name".equals(jp.getCurrentName())) {
        term.setName(jp.nextTextValue());
      } else if ("Type".equals(jp.getCurrentName())) {
        term.setType(jp.nextTextValue());
      } else if ("BaseTerm".equals(jp.getCurrentName())) {
        term.setBaseTerm(jp.nextTextValue());
      } else if ("DefaultValue".equals(jp.getCurrentName())) {
        term.setDefaultValue(jp.nextTextValue());
      } else if ("Nullable".equals(jp.getCurrentName())) {
        term.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
      } else if ("MaxLength".equals(jp.getCurrentName())) {
        final String maxLenght = jp.nextTextValue();
        term.setMaxLength("max".equalsIgnoreCase(maxLenght) ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
      } else if ("Precision".equals(jp.getCurrentName())) {
        term.setPrecision(Integer.valueOf(jp.nextTextValue()));
      } else if ("Scale".equals(jp.getCurrentName())) {
        final String scale = jp.nextTextValue();
        term.setScale("variable".equalsIgnoreCase(scale) || "floating".equalsIgnoreCase(scale) ?
            0 : Integer.valueOf(scale));
      } else if ("SRID".equals(jp.getCurrentName())) {
        final String srid = jp.nextTextValue();
        if (srid != null) {
          term.setSrid(SRID.valueOf(srid));
        }
      } else if ("AppliesTo".equals(jp.getCurrentName())) {
        term.getAppliesTo().addAll(Arrays.asList(StringUtils.split(jp.nextTextValue())));
      } else if ("Annotation".equals(jp.getCurrentName())) {
        jp.nextToken();
        term.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class));
      }
    }
  }

  return term;
}
 
Example 20
Source File: TimeSeries.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
static List<TimeSeries> parseJson(JsonParser parser, boolean single) {
    Objects.requireNonNull(parser);
    List<TimeSeries> timeSeriesList = new ArrayList<>();
    try {
        TimeSeriesMetadata metadata = null;
        String name = null;
        JsonToken token;
        while ((token = parser.nextToken()) != null) {
            if (token == JsonToken.FIELD_NAME) {
                String fieldName = parser.getCurrentName();
                switch (fieldName) {
                    case "metadata":
                        metadata = TimeSeriesMetadata.parseJson(parser);
                        break;
                    case "chunks":
                        if (metadata == null) {
                            throw new TimeSeriesException("metadata is null");
                        }
                        parseChunks(parser, metadata, timeSeriesList);
                        metadata = null;
                        break;
                    case "name":
                        name = parser.nextTextValue();
                        break;
                    case "expr":
                        Objects.requireNonNull(name);
                        NodeCalc nodeCalc = NodeCalc.parseJson(parser);
                        timeSeriesList.add(new CalculatedTimeSeries(name, nodeCalc));
                        break;
                    default:
                        break;
                }
            } else if (token == JsonToken.END_OBJECT && single) {
                break;
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return timeSeriesList;
}