io.rebind.vertx.orientdb.model.RecordConverter.java Source code

Java tutorial

Introduction

Here is the source code for io.rebind.vertx.orientdb.model.RecordConverter.java

Source

/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.rebind.vertx.orientdb.model;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

/**
 * Converter for {@link io.rebind.vertx.orientdb.model.Record}.
 *
 * NOTE: This class has been automatically generated from the {@link io.rebind.vertx.orientdb.model.Record} original class using Vert.x codegen.
 */
public class RecordConverter {

    public static void fromJson(JsonObject json, Record obj) {
        if (json.getValue("connections") instanceof JsonArray) {
            java.util.ArrayList<io.rebind.vertx.orientdb.model.Connection> list = new java.util.ArrayList<>();
            json.getJsonArray("connections").forEach(item -> {
                if (item instanceof JsonObject)
                    list.add(new io.rebind.vertx.orientdb.model.Connection((JsonObject) item));
            });
            obj.setConnections(list);
        }
        if (json.getValue("iClass") instanceof String) {
            obj.setIClass((String) json.getValue("iClass"));
        }
        if (json.getValue("properties") instanceof JsonObject) {
            obj.setProperties(((JsonObject) json.getValue("properties")).copy());
        }
        if (json.getValue("rid") instanceof String) {
            obj.setRid((String) json.getValue("rid"));
        }
        if (json.getValue("version") instanceof Number) {
            obj.setVersion(((Number) json.getValue("version")).intValue());
        }
    }

    public static void toJson(Record obj, JsonObject json) {
        if (obj.getConnections() != null) {
            json.put("connections", new JsonArray(obj.getConnections().stream().map(item -> item.toJson())
                    .collect(java.util.stream.Collectors.toList())));
        }
        if (obj.getProperties() != null) {
            json.put("properties", obj.getProperties());
        }
        if (obj.getRid() != null) {
            json.put("rid", obj.getRid());
        }
        if (obj.getVersion() != null) {
            json.put("version", obj.getVersion());
        }
    }
}