Package org.cometd.common
Interface JSONContext<T extends Message.Mutable>
-
- Type Parameters:
T
- the type of message
- All Known Subinterfaces:
JSONContext.Client
,JSONContextServer
- All Known Implementing Classes:
JacksonJSONContextClient
,JacksonJSONContextServer
,JettyJSONContextClient
,JettyJSONContextServer
public interface JSONContext<T extends Message.Mutable>
Abstraction for JSON parsing and generation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
JSONContext.AsyncParser
A non-blocking JSON parser.static interface
JSONContext.Client
Client specificJSONContext
that binds toMessage.Mutable
.static interface
JSONContext.Generator
A JSON stringifier.static interface
JSONContext.Parser
A blocking JSON parser.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.lang.String
generate(java.util.List<T> messages)
Converts a list of messages to a JSON string.java.lang.String
generate(T message)
Converts a single message to a JSON string.JSONContext.Generator
getGenerator()
JSONContext.Parser
getParser()
default JSONContext.AsyncParser
newAsyncParser()
T[]
parse(java.io.Reader reader)
Parses an array of messages from the given reader.T[]
parse(java.lang.String json)
Parses an array of messages from the given string.
-
-
-
Method Detail
-
parse
T[] parse(java.io.Reader reader) throws java.text.ParseException
Parses an array of messages from the given reader.
- Parameters:
reader
- the reader to parse from- Returns:
- an array of messages
- Throws:
java.text.ParseException
- in case of parsing errors
-
parse
T[] parse(java.lang.String json) throws java.text.ParseException
Parses an array of messages from the given string.
- Parameters:
json
- the JSON string to parse from- Returns:
- an array of messages
- Throws:
java.text.ParseException
- in case of parsing errors
-
newAsyncParser
default JSONContext.AsyncParser newAsyncParser()
- Returns:
- a new
JSONContext.AsyncParser
instance, or null if non-blocking parsing is not supported
-
generate
java.lang.String generate(T message)
Converts a single message to a JSON string.
- Parameters:
message
- the message to stringify- Returns:
- the JSON string for the message
-
generate
java.lang.String generate(java.util.List<T> messages)
Converts a list of messages to a JSON string.
- Parameters:
messages
- the list of messages to stringify- Returns:
- the JSON string for the messages
-
getParser
JSONContext.Parser getParser()
- Returns:
- a synchronous JSON parser to parse any JSON string
-
getGenerator
JSONContext.Generator getGenerator()
- Returns:
- a JSON generator to stringify any object to a JSON string
-
-