public final class JsonStringEncoder extends Object
Note that methods in here are somewhat optimized, but not ridiculously so. Reason is that conversion method results are expected to be cached so that these methods will not be hot spots during normal operation.
Constructor and Description |
---|
JsonStringEncoder() |
Modifier and Type | Method and Description |
---|---|
byte[] |
encodeAsUTF8(CharSequence text)
Overloaded variant of
encodeAsUTF8(String) . |
byte[] |
encodeAsUTF8(String text)
Will encode given String as UTF-8 (without any escaping) and return
the resulting byte array.
|
static JsonStringEncoder |
getInstance()
Factory method for getting an instance; this is either recycled per-thread instance,
or a newly constructed one.
|
char[] |
quoteAsString(CharSequence input)
Overloaded variant of
quoteAsString(String) . |
void |
quoteAsString(CharSequence input,
StringBuilder output)
Method that will quote text contents using JSON standard quoting,
and append results to a supplied
StringBuilder . |
char[] |
quoteAsString(String input)
Method that will escape text contents using JSON standard escaping,
and return results as a character array.
|
byte[] |
quoteAsUTF8(String text)
Method that will escape text contents using JSON standard escaping,
encode resulting String as UTF-8 bytes
and return results as a byte array.
|
public static JsonStringEncoder getInstance()
public char[] quoteAsString(String input)
input
- Value String to processinput
public char[] quoteAsString(CharSequence input)
quoteAsString(String)
.input
- Value CharSequence
to processinput
public void quoteAsString(CharSequence input, StringBuilder output)
StringBuilder
.
Use this variant if you have e.g. a StringBuilder
and want to avoid superfluous copying of it.input
- Value CharSequence
to processoutput
- StringBuilder
to append escaped contents topublic byte[] quoteAsUTF8(String text)
text
- Value String
to processtext
public byte[] encodeAsUTF8(String text)
text
- Value String
to processtext
(without any escaping)public byte[] encodeAsUTF8(CharSequence text)
encodeAsUTF8(String)
.text
- Value CharSequence
to processtext
(without any escaping)Copyright © 2008–2021 FasterXML. All rights reserved.