use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.SerializableString in project jackson-core by FasterXML.
the class TestSerializedString method testFailedAccess.
public void testFailedAccess() throws IOException {
final String INPUT = "Bit longer text";
SerializableString sstr = new SerializedString(INPUT);
final byte[] buffer = new byte[INPUT.length() - 2];
final char[] ch = new char[INPUT.length() - 2];
final ByteBuffer bbuf = ByteBuffer.allocate(INPUT.length() - 2);
assertEquals(-1, sstr.appendQuotedUTF8(buffer, 0));
assertEquals(-1, sstr.appendQuoted(ch, 0));
assertEquals(-1, sstr.putQuotedUTF8(bbuf));
bbuf.rewind();
assertEquals(-1, sstr.appendUnquotedUTF8(buffer, 0));
assertEquals(-1, sstr.appendUnquoted(ch, 0));
assertEquals(-1, sstr.putUnquotedUTF8(bbuf));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.SerializableString in project jackson-databind by FasterXML.
the class WritableObjectId method writeAsField.
/**
* Method called to output Object Id as specified.
*/
public void writeAsField(JsonGenerator gen, SerializerProvider provider, ObjectIdWriter w) throws IOException {
idWritten = true;
// 03-Aug-2013, tatu: Prefer Native Object Ids if available
if (gen.canWriteObjectId()) {
// Need to assume String(ified) ids, for now... could add 'long' variant?
gen.writeObjectId(String.valueOf(id));
return;
}
SerializableString name = w.propertyName;
if (name != null) {
gen.writeFieldName(name);
w.serializer.serialize(id, gen, provider);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.SerializableString in project jackson-databind by FasterXML.
the class EnumValues method constructFromName.
public static EnumValues constructFromName(MapperConfig<?> config, Class<Enum<?>> enumClass) {
// Enum types with per-instance sub-classes need special handling
Class<? extends Enum<?>> enumCls = ClassUtil.findEnumType(enumClass);
Enum<?>[] enumValues = enumCls.getEnumConstants();
if (enumValues == null) {
throw new IllegalArgumentException("Can not determine enum constants for Class " + enumClass.getName());
}
String[] names = config.getAnnotationIntrospector().findEnumValues(enumCls, enumValues, new String[enumValues.length]);
SerializableString[] textual = new SerializableString[enumValues.length];
for (int i = 0, len = enumValues.length; i < len; ++i) {
Enum<?> en = enumValues[i];
String name = names[i];
if (name == null) {
name = en.name();
}
textual[en.ordinal()] = config.compileString(name);
}
return new EnumValues(enumClass, textual);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.SerializableString in project jackson-databind by FasterXML.
the class TestGeneratorUsingMapper method testIssue820.
public void testIssue820() throws IOException {
StringBuffer sb = new StringBuffer();
while (sb.length() <= 5000) {
sb.append("Yet another line of text...\n");
}
String sampleText = sb.toString();
assertTrue("Sanity check so I don't mess up the sample text later.", sampleText.contains("\n"));
final ObjectMapper mapper = new ObjectMapper();
final CharacterEscapes defaultCharacterEscapes = new CharacterEscapes() {
private static final long serialVersionUID = 1L;
@Override
public int[] getEscapeCodesForAscii() {
return standardAsciiEscapesForJSON();
}
@Override
public SerializableString getEscapeSequence(final int ch) {
return null;
}
};
mapper.getFactory().setCharacterEscapes(defaultCharacterEscapes);
String jacksonJson = mapper.writeValueAsString(sampleText);
boolean hasLFs = jacksonJson.indexOf('\n') > 0;
assertFalse("Should NOT contain linefeeds, should have been escaped", hasLFs);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.SerializableString in project bson4jackson by michel-kraemer.
the class BsonGenerator method escapeCharacters.
/**
* Escapes the given string according to {@link #_characterEscapes}. If
* there are no character escapes returns the original string.
* @param string the string to escape
* @return the escaped string or the original one if there is nothing to escape
* @throws IOException if an escape sequence could not be retrieved
*/
protected String escapeCharacters(String string) throws IOException {
if (_characterEscapes == null) {
// escaping not necessary
return string;
}
StringBuilder sb = null;
int lastEscapePos = 0;
for (int i = 0; i < string.length(); ++i) {
int c = string.charAt(i);
if (c <= 0x7F && _outputEscapes[c] == CharacterEscapes.ESCAPE_CUSTOM) {
SerializableString escape = _characterEscapes.getEscapeSequence(c);
if (escape == null) {
_reportError("Invalid custom escape definitions; custom escape " + "not found for character code 0x" + Integer.toHexString(c) + ", although was supposed to have one");
}
if (sb == null) {
sb = new StringBuilder();
}
if (i > lastEscapePos) {
sb.append(string, lastEscapePos, i);
}
lastEscapePos = i + 1;
sb.append(escape.getValue());
}
}
if (sb != null && lastEscapePos < string.length()) {
sb.append(string, lastEscapePos, string.length());
}
if (sb == null) {
return string;
}
return sb.toString();
}
Aggregations