net.anwiba.tools.definition.schema.json.gramma.element.JValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of anwiba-tools-definition-schema-json Show documentation
Show all versions of anwiba-tools-definition-schema-json Show documentation
JSON like gramma Data Type definition language JSSD and Java class generator for Jackson Framework JSON-structure reading and writing
The newest version!
/*
* #%L
* anwiba commons tools
* %%
* Copyright (C) 2007 - 2016 Andreas Bartels
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package net.anwiba.tools.definition.schema.json.gramma.element;
import java.util.List;
public class JValue implements IJNode {
private final Object value;
private final JsonType type;
public JValue(final Object value) {
this.value = value;
this.type = createType(value);
}
@SuppressWarnings("unchecked")
public T value() {
return (T) this.value;
}
public JsonType type() {
return this.type;
}
private JsonType createType(final Object object) {
if (object instanceof JObject) {
return JsonType.OBJECT;
}
if (object instanceof List) {
return JsonType.ARRAY;
}
if (object == null) {
return JsonType.NULL;
}
if (object instanceof String) {
return JsonType.STRING;
}
if (object instanceof Number) {
return JsonType.NUMBER;
}
if (object instanceof Boolean) {
return JsonType.BOOLEAN;
}
if (object instanceof Character) {
return JsonType.CHARACTER;
}
throw new IllegalArgumentException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy