Example usage for com.badlogic.gdx.utils UBJsonWriter value

List of usage examples for com.badlogic.gdx.utils UBJsonWriter value

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils UBJsonWriter value.

Prototype

public UBJsonWriter value(Object object) throws IOException 

Source Link

Document

Appends the object to the stream, if it is a known value type.

Usage

From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java

License:Apache License

private void writeObject(JsonValue root, UBJsonWriter writer) throws IOException {
    if (root.type() == ValueType.array) {
        if (root.name() != null) {
            writer.array(root.name());//from  w w  w  .j av a  2s .co m
        } else {
            writer.array();
        }
    } else {
        if (root.name() != null) {
            writer.object(root.name());
        } else {
            writer.object();
        }
    }

    JsonValue child = root.child();
    while (child != null) {
        switch (child.type()) {
        case booleanValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asBoolean());
            } else {
                writer.value(child.asBoolean());
            }
            break;

        case doubleValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asDouble());
            } else {
                writer.value(child.asDouble());
            }
            break;

        case longValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asLong());
            } else {
                writer.value(child.asLong());
            }
            break;

        case stringValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asString());
            } else {
                writer.value(child.asString());
            }
            break;

        case nullValue:
            if (child.name() != null) {
                writer.set(child.name());
            }
            break;

        case array:
        case object:
            writeObject(child, writer);
            break;
        }

        child = child.next();
    }

    writer.pop();
}