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

panda.cast.castor.JsonObjectCastor Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.cast.castor;

import panda.bind.json.JsonException;
import panda.bind.json.JsonObject;
import panda.cast.CastContext;
import panda.lang.Strings;


public class JsonObjectCastor extends AnySingleCastor {
	public JsonObjectCastor() {
		super(JsonObject.class);
	}

	@Override
	protected JsonObject castValue(Object value, CastContext cc) {
		if (value instanceof CharSequence) {
			String s = value.toString();
			if (Strings.isEmpty(s)) {
				return defaultValue();
			}

			try {
				return JsonObject.fromJson(s);
			}
			catch (JsonException e) {
				return castError(value, cc, e);
			}
		}
		
		return castError(value, cc);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy