
org.directwebremoting.json.JsonUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dwr Show documentation
Show all versions of dwr Show documentation
DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript.
It gets rid of almost all the boilerplate code between the web browser and your Java code.
This version 4.0.2 works with Jakarta Servlet 4.0.2.
The newest version!
package org.directwebremoting.json;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;
import java.util.Map;
import org.directwebremoting.json.parse.JsonParseException;
import org.directwebremoting.json.parse.JsonParser;
import org.directwebremoting.json.parse.JsonParserFactory;
import org.directwebremoting.json.parse.impl.IgnoreJsonDecoder;
import org.directwebremoting.json.parse.impl.ReflectionJsonDecoder;
import org.directwebremoting.json.parse.impl.SimpleJsonDecoder;
import org.directwebremoting.json.serialize.JsonSerializer;
import org.directwebremoting.json.serialize.JsonSerializerFactory;
/**
* Various utilities to make parsing and reading JSON easier
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class JsonUtil
{
/**
* Get a record of any errors in parsing the input string
* @param input ...
* @return ...
*/
public static String getErrors(String input)
{
return getErrors(new StringReader(input));
}
/**
* Get a record of any errors in parsing the input document
* @param reader ...
* @return ...
*/
public static String getErrors(Reader reader)
{
try
{
JsonParser parser = JsonParserFactory.get();
parser.parse(reader, new IgnoreJsonDecoder());
return null;
}
catch (JsonParseException ex)
{
return ex.toString();
}
}
/**
* Convert the input string into a set of basic types
* @param input ...
* @return ...
* @throws JsonParseException ...
*/
public static Map toSimpleObject(String input) throws JsonParseException
{
return toSimpleObject(new StringReader(input));
}
/**
* Convert the input document into a set of basic types
* @param reader ...
* @return ...
* @throws JsonParseException ...
*/
@SuppressWarnings("unchecked")
public static Map toSimpleObject(Reader reader) throws JsonParseException
{
JsonParser parser = JsonParserFactory.get();
return (Map) parser.parse(reader, new SimpleJsonDecoder());
}
/**
* Convert the input string into a set of basic types
* @param input ...
* @return ...
* @throws JsonParseException ...
*/
public static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy