public void testAppending() throws IOException { final String INPUT = "\"quo\\ted\""; final String QUOTED = "\\\"quo\\\\ted\\\""; SerializableString sstr = new SerializedString(INPUT); // sanity checks first: assertEquals(sstr.getValue(), INPUT); assertEquals(QUOTED, new String(sstr.asQuotedChars())); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); assertEquals(QUOTED.length(), sstr.writeQuotedUTF8(bytes)); assertEquals(QUOTED, bytes.toString("UTF-8")); bytes.reset(); assertEquals(INPUT.length(), sstr.writeUnquotedUTF8(bytes)); assertEquals(INPUT, bytes.toString("UTF-8")); byte[] buffer = new byte[100]; assertEquals(QUOTED.length(), sstr.appendQuotedUTF8(buffer, 3)); assertEquals(QUOTED, new String(buffer, 3, QUOTED.length())); Arrays.fill(buffer, (byte) 0); assertEquals(INPUT.length(), sstr.appendUnquotedUTF8(buffer, 5)); assertEquals(INPUT, new String(buffer, 5, INPUT.length())); }
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)); }
private void _testIsNextTokenName4(int mode) throws Exception { final String DOC = "{\"name\":-123,\"name2\":99}"; JsonParser p = createParser(mode, DOC); assertToken(JsonToken.START_OBJECT, p.nextToken()); assertTrue(p.nextFieldName(new SerializedString("name"))); assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken()); assertEquals(-123, p.getIntValue()); assertTrue(p.nextFieldName(new SerializedString("name2"))); assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken()); assertEquals(99, p.getIntValue()); assertToken(JsonToken.END_OBJECT, p.nextToken()); if (mode != MODE_DATA_INPUT) { assertNull(p.nextToken()); } p.close(); }
protected BeanPropertyWriter(BeanPropertyWriter base, SerializedString name) { _name = name; _wrapperName = base._wrapperName; _member = base._member; _contextAnnotations = base._contextAnnotations; _declaredType = base._declaredType; _accessorMethod = base._accessorMethod; _field = base._field; _serializer = base._serializer; _nullSerializer = base._nullSerializer; // one more thing: copy internal settings, if any (since 1.7) if (base._internalSettings != null) { _internalSettings = new HashMap<Object,Object>(base._internalSettings); } _cfgSerializationType = base._cfgSerializationType; _dynamicSerializers = base._dynamicSerializers; _suppressNulls = base._suppressNulls; _suppressableValue = base._suppressableValue; _includeInViews = base._includeInViews; _typeSerializer = base._typeSerializer; _nonTrivialBaseType = base._nonTrivialBaseType; _metadata = base._metadata; }
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType) { if (paramJsonFormatVisitorWrapper.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType); if (localJsonIntegerFormatVisitor != null) localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.INT); return; } JsonStringFormatVisitor localJsonStringFormatVisitor = paramJsonFormatVisitorWrapper.expectStringFormat(paramJavaType); if ((paramJavaType != null) && (localJsonStringFormatVisitor != null) && (paramJavaType.isEnumType())) { LinkedHashSet localLinkedHashSet = new LinkedHashSet(); Iterator localIterator = this._values.values().iterator(); while (localIterator.hasNext()) localLinkedHashSet.add(((SerializedString)localIterator.next()).getValue()); localJsonStringFormatVisitor.enumTypes(localLinkedHashSet); } }
public BeanPropertyWriter(BeanPropertyWriter paramBeanPropertyWriter, SerializedString paramSerializedString) { this._name = paramSerializedString; this._wrapperName = paramBeanPropertyWriter._wrapperName; this._member = paramBeanPropertyWriter._member; this._contextAnnotations = paramBeanPropertyWriter._contextAnnotations; this._declaredType = paramBeanPropertyWriter._declaredType; this._accessorMethod = paramBeanPropertyWriter._accessorMethod; this._field = paramBeanPropertyWriter._field; this._serializer = paramBeanPropertyWriter._serializer; this._nullSerializer = paramBeanPropertyWriter._nullSerializer; if (paramBeanPropertyWriter._internalSettings != null) this._internalSettings = new HashMap(paramBeanPropertyWriter._internalSettings); this._cfgSerializationType = paramBeanPropertyWriter._cfgSerializationType; this._dynamicSerializers = paramBeanPropertyWriter._dynamicSerializers; this._suppressNulls = paramBeanPropertyWriter._suppressNulls; this._suppressableValue = paramBeanPropertyWriter._suppressableValue; this._includeInViews = paramBeanPropertyWriter._includeInViews; this._typeSerializer = paramBeanPropertyWriter._typeSerializer; this._nonTrivialBaseType = paramBeanPropertyWriter._nonTrivialBaseType; this._isRequired = paramBeanPropertyWriter._isRequired; }
public static EnumValues constructFromName(Class<Enum<?>> paramClass, AnnotationIntrospector paramAnnotationIntrospector) { Enum[] arrayOfEnum = (Enum[])ClassUtil.findEnumType(paramClass).getEnumConstants(); if (arrayOfEnum != null) { HashMap localHashMap = new HashMap(); int i = arrayOfEnum.length; for (int j = 0; j < i; j++) { Enum localEnum = arrayOfEnum[j]; localHashMap.put(localEnum, new SerializedString(paramAnnotationIntrospector.findEnumValue(localEnum))); } return new EnumValues(paramClass, localHashMap); } throw new IllegalArgumentException("Can not determine enum constants for Class " + paramClass.getName()); }
public static EnumValues constructFromToString(Class<Enum<?>> paramClass, AnnotationIntrospector paramAnnotationIntrospector) { Enum[] arrayOfEnum = (Enum[])ClassUtil.findEnumType(paramClass).getEnumConstants(); if (arrayOfEnum != null) { HashMap localHashMap = new HashMap(); int i = arrayOfEnum.length; for (int j = 0; j < i; j++) { Enum localEnum = arrayOfEnum[j]; localHashMap.put(localEnum, new SerializedString(localEnum.toString())); } return new EnumValues(paramClass, localHashMap); } throw new IllegalArgumentException("Can not determine enum constants for Class " + paramClass.getName()); }
public FSTJsonFieldNames(final String TYPE, final String OBJ, final String SEQ_TYPE, final String SEQ, final String ENUM, final String VAL, final String REF) { this.TYPE = TYPE; this.OBJ = OBJ; this.SEQ_TYPE = SEQ_TYPE; this.SEQ = SEQ; this.ENUM = ENUM; this.VAL = VAL; this.REF = REF; this.TYPE_S = new SerializedString(TYPE); this.OBJ_S = new SerializedString(OBJ); this.SEQ_TYPE_S = new SerializedString(SEQ_TYPE); this.SEQ_S = new SerializedString(SEQ); this.ENUM_S = new SerializedString(ENUM); this.VAL_S = new SerializedString(VAL); this.REF_S = new SerializedString(REF); }
@Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) { // [JACKSON-684]: serialize as index? if (_serializeAsIndex(provider)) { return createSchemaNode("integer", true); } ObjectNode objectNode = createSchemaNode("string", true); if (typeHint != null) { JavaType type = provider.constructType(typeHint); if (type.isEnumType()) { ArrayNode enumNode = objectNode.putArray("enum"); for (SerializedString value : _values.values()) { enumNode.add(value.getValue()); } } } return objectNode; }
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { // [JACKSON-684]: serialize as index? if (visitor.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { visitor.expectIntegerFormat(typeHint); } else { JsonStringFormatVisitor stringVisitor = visitor.expectStringFormat(typeHint); if (typeHint != null) { if (typeHint.isEnumType()) { Set<String> enums = new HashSet<String>(); for (SerializedString value : _values.values()) { enums.add(value.getValue()); } stringVisitor.enumTypes(enums); } } } }
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { JsonObjectFormatVisitor objectVisitor = visitor.expectObjectFormat(typeHint); /* JavaType enumType = typeHint.containedType(0); if (enumType == null) { enumType = visitor.getProvider().constructType(Object.class); } */ JavaType valueType = typeHint.containedType(1); if (valueType == null) { valueType = visitor.getProvider().constructType(Object.class); } JsonSerializer<Object> ser = _valueSerializer; // Class<Enum<?>> enumClass = (Class<Enum<?>>) enumType.getRawClass(); for (Map.Entry<?,SerializedString> entry : _keyEnums.internalMap().entrySet()) { String name = entry.getValue().getValue(); // should all have the same type, so: if (ser == null) { ser = visitor.getProvider().findValueSerializer(entry.getKey().getClass(), _property); } objectVisitor.property(name, (JsonFormatVisitable) ser, valueType); } }
protected BeanPropertyWriter(BeanPropertyWriter base, SerializedString name) { _name = name; _member = base._member; _contextAnnotations = base._contextAnnotations; _declaredType = base._declaredType; _accessorMethod = base._accessorMethod; _field = base._field; _serializer = base._serializer; _nullSerializer = base._nullSerializer; // one more thing: copy internal settings, if any (since 1.7) if (base._internalSettings != null) { _internalSettings = new HashMap<Object,Object>(base._internalSettings); } _cfgSerializationType = base._cfgSerializationType; _dynamicSerializers = base._dynamicSerializers; _suppressNulls = base._suppressNulls; _suppressableValue = base._suppressableValue; _includeInViews = base._includeInViews; _typeSerializer = base._typeSerializer; _nonTrivialBaseType = base._nonTrivialBaseType; }
public static EnumValues constructFromName(Class<Enum<?>> enumClass, AnnotationIntrospector intr) { /* [JACKSON-214]: Enum types with per-instance sub-classes * need special handling */ Class<? extends Enum<?>> cls = ClassUtil.findEnumType(enumClass); Enum<?>[] values = cls.getEnumConstants(); if (values != null) { // Type juggling... unfortunate Map<Enum<?>,SerializedString> map = new HashMap<Enum<?>,SerializedString>(); for (Enum<?> en : values) { String value = intr.findEnumValue(en); map.put(en, new SerializedString(value)); } return new EnumValues(map); } throw new IllegalArgumentException("Can not determine enum constants for Class "+enumClass.getName()); }
/** * By default JSON output does only have escaping where it is strictly * necessary. This is recommended in the most cases. Nevertheless it can * be sometimes useful to have some more escaping. * * @param escapeCharacters an array which defines which characters should be * escaped and how it will be done. See * {@link CharacterEscapes}. In most cases this should * be null. Use like this: * <pre>{@code int[] esc = CharacterEscapes.standardAsciiEscapesForJSON(); * // and force escaping of a few others: * esc['\''] = CharacterEscapes.ESCAPE_STANDARD; * JsonEncoder.useEscapeJavaScript(esc); * }</pre> */ public void setJavaScriptEscapeChars(final int[] escapeCharacters) { final CharacterEscapes ce = new CharacterEscapes() { private static final long serialVersionUID = 1L; @Override public int[] getEscapeCodesForAscii() { if (escapeCharacters == null) { return CharacterEscapes.standardAsciiEscapesForJSON(); } return escapeCharacters; } @Override public SerializableString getEscapeSequence(final int ch) { final String jsEscaped = escapeChar((char) ch); return new SerializedString(jsEscaped); } }; jsonGenerator.setCharacterEscapes(ce); }
private void _testWithRaw(JsonFactory f, boolean useBytes) throws Exception { JsonGenerator g; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); StringWriter sw = new StringWriter(); if (useBytes) { g = f.createGenerator(ObjectWriteContext.empty(), bytes, JsonEncoding.UTF8); } else { g = f.createGenerator(ObjectWriteContext.empty(), sw); } g.writeStartArray(); g.writeRawValue(new SerializedString("\"foo\"")); g.writeRawValue(new SerializedString("12")); g.writeRaw(new SerializedString(", false")); g.writeEndArray(); g.close(); JsonParser p = useBytes ? f.createParser(ObjectReadContext.empty(), bytes.toByteArray()) : f.createParser(ObjectReadContext.empty(), sw.toString()); assertToken(JsonToken.START_ARRAY, p.nextToken()); assertToken(JsonToken.VALUE_STRING, p.nextToken()); assertEquals("foo", p.getText()); assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken()); assertEquals(12, p.getIntValue()); assertToken(JsonToken.VALUE_FALSE, p.nextToken()); assertToken(JsonToken.END_ARRAY, p.nextToken()); p.close(); }
@Override public SerializableString getEscapeSequence(int ch) { if (ch == 'd') { return new SerializedString("[D]"); } if (ch == TWO_BYTE_ESCAPED) { return TWO_BYTE_ESCAPED_STRING; } if (ch == THREE_BYTE_ESCAPED) { return THREE_BYTE_ESCAPED_STRING; } return null; }
public void testSingleMatchFilteringWithPathAlternate1() throws Exception { StringWriter w = new StringWriter(); FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(JSON_F.createGenerator(ObjectWriteContext.empty(), w), new NameMatchFilter("value"), true, // includePath false // multipleMatches ); //final String JSON = "{'a':123,'array':[1,2],'ob':{'value0':2,'value':[3],'value2':'foo'},'b':true}"; gen.writeStartObject(); gen.writeFieldName(new SerializedString("a")); gen.writeNumber(123); gen.writeFieldName("array"); gen.writeStartArray(2); gen.writeNumber("1"); gen.writeNumber((short) 2); gen.writeEndArray(); gen.writeFieldName(new SerializedString("ob")); gen.writeStartObject(); gen.writeNumberField("value0", 2); gen.writeFieldName(new SerializedString("value")); gen.writeStartArray(1); gen.writeString(new SerializedString("x")); // just to vary generation method gen.writeEndArray(); gen.writeStringField("value2", "foo"); gen.writeEndObject(); gen.writeBooleanField("b", true); gen.writeEndObject(); gen.close(); assertEquals(aposToQuotes("{'ob':{'value':['x']}}"), w.toString()); assertEquals(1, gen.getMatchCount()); }
@Test public void testObjectTrailingCommaWithNextFieldNameStr() throws Exception { String json = "{\"a\": true, \"b\": false,}"; JsonParser p = createParser(factory, mode, json); assertEquals(JsonToken.START_OBJECT, p.nextToken()); assertTrue(p.nextFieldName(new SerializedString("a"))); assertToken(JsonToken.VALUE_TRUE, p.nextToken()); assertTrue(p.nextFieldName(new SerializedString("b"))); assertToken(JsonToken.VALUE_FALSE, p.nextToken()); if (features.contains(Feature.ALLOW_TRAILING_COMMA)) { assertFalse(p.nextFieldName(new SerializedString("c"))); assertToken(JsonToken.END_OBJECT, p.currentToken()); assertEnd(p); } else { try { p.nextFieldName(new SerializedString("c")); fail("No exception thrown"); } catch (Exception e) { verifyException(e, "Unexpected character ('}' (code 125))"); } } p.close(); }
private void _testIsNextTokenName2(int mode) throws Exception { final String DOC = "{\"name\":123,\"name2\":14,\"x\":\"name\"}"; JsonParser p = createParser(mode, DOC); SerializableString NAME = new SerializedString("name"); assertFalse(p.nextFieldName(NAME)); assertToken(JsonToken.START_OBJECT, p.currentToken()); assertTrue(p.nextFieldName(NAME)); assertToken(JsonToken.FIELD_NAME, p.currentToken()); assertEquals(NAME.getValue(), p.currentName()); assertEquals(NAME.getValue(), p.getText()); assertFalse(p.nextFieldName(NAME)); assertToken(JsonToken.VALUE_NUMBER_INT, p.currentToken()); assertEquals(123, p.getIntValue()); assertFalse(p.nextFieldName(NAME)); assertToken(JsonToken.FIELD_NAME, p.currentToken()); assertEquals("name2", p.currentName()); assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken()); assertFalse(p.nextFieldName(NAME)); assertToken(JsonToken.FIELD_NAME, p.currentToken()); assertEquals("x", p.currentName()); assertFalse(p.nextFieldName(NAME)); assertToken(JsonToken.VALUE_STRING, p.currentToken()); assertFalse(p.nextFieldName(NAME)); assertToken(JsonToken.END_OBJECT, p.currentToken()); if (mode != MODE_DATA_INPUT) { assertFalse(p.nextFieldName(NAME)); assertNull(p.currentToken()); } p.close(); }
private void _testNextFieldNameIndent(int mode) throws Exception { final String DOC = "{\n \"name\" : \n [\n ]\n }"; JsonParser p = createParser(mode, DOC); assertToken(JsonToken.START_OBJECT, p.nextToken()); assertTrue(p.nextFieldName(new SerializedString("name"))); assertToken(JsonToken.START_ARRAY, p.nextToken()); assertToken(JsonToken.END_ARRAY, p.nextToken()); assertToken(JsonToken.END_OBJECT, p.nextToken()); if (mode != MODE_DATA_INPUT) { assertNull(p.nextToken()); } p.close(); }
private void _testIssue34(int mode) throws Exception { final int TESTROUNDS = 223; final String DOC_PART = "{ \"fieldName\": 1 }"; // build the big document to trigger issue StringBuilder sb = new StringBuilder(2000); for (int i = 0; i < TESTROUNDS; ++i) { sb.append(DOC_PART); } final String DOC = sb.toString(); SerializableString fieldName = new SerializedString("fieldName"); JsonParser parser = createParser(mode, DOC); for (int i = 0; i < TESTROUNDS - 1; i++) { assertEquals(JsonToken.START_OBJECT, parser.nextToken()); // These will succeed assertTrue(parser.nextFieldName(fieldName)); parser.nextLongValue(-1); assertEquals(JsonToken.END_OBJECT, parser.nextToken()); } assertEquals(JsonToken.START_OBJECT, parser.nextToken()); // This will fail assertTrue(parser.nextFieldName(fieldName)); parser.close(); }
private void _testIssue38(int mode) throws Exception { final String DOC = "{\"field\" :\"value\"}"; SerializableString fieldName = new SerializedString("field"); JsonParser parser = createParser(mode, DOC); assertEquals(JsonToken.START_OBJECT, parser.nextToken()); assertTrue(parser.nextFieldName(fieldName)); assertEquals(JsonToken.VALUE_STRING, parser.nextToken()); assertEquals("value", parser.getText()); assertEquals(JsonToken.END_OBJECT, parser.nextToken()); if (mode != MODE_DATA_INPUT) { assertNull(parser.nextToken()); } parser.close(); }
private void _testNextFieldName(int mode, byte[] doc) throws IOException { SerializedString id = new SerializedString("id"); JsonParser parser = createParser(mode, doc); assertEquals(parser.nextToken(), JsonToken.START_OBJECT); assertTrue(parser.nextFieldName(id)); assertEquals(parser.nextToken(), JsonToken.VALUE_NUMBER_INT); assertEquals(parser.nextToken(), JsonToken.END_OBJECT); parser.close(); }
static SerializedString serializeString(String name) { SerializedString s = new SerializedString(name); // Eagerly compute encodings. s.asQuotedChars(); s.asQuotedUTF8(); s.asUnquotedUTF8(); return s; }
@SuppressWarnings("unchecked") public BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, Object suppressableValue) { _member = member; _contextAnnotations = contextAnnotations; _name = new SerializedString(propDef.getName()); _wrapperName = propDef.getWrapperName(); _declaredType = declaredType; _serializer = (JsonSerializer<Object>) ser; _dynamicSerializers = (ser == null) ? PropertySerializerMap.emptyMap() : null; _typeSerializer = typeSer; _cfgSerializationType = serType; _metadata = propDef.getMetadata(); if (member instanceof AnnotatedField) { _accessorMethod = null; _field = (Field) member.getMember(); } else if (member instanceof AnnotatedMethod) { _accessorMethod = (Method) member.getMember(); _field = null; } else { throw new IllegalArgumentException("Can not pass member of type "+member.getClass().getName()); } _suppressNulls = suppressNulls; _suppressableValue = suppressableValue; _includeInViews = propDef.findViews(); // this will be resolved later on, unless nulls are to be suppressed _nullSerializer = null; }
public BeanPropertyWriter rename(NameTransformer transformer) { String newName = transformer.transform(_name.getValue()); if (newName.equals(_name.toString())) { return this; } return new BeanPropertyWriter(this, new SerializedString(newName)); }
@Override public SerializableString getEscapeSequence(int ch) { if (ch == '<') { return new SerializedString("<"); } if (ch == '>') { return new SerializedString(">"); } return null; }
@Override public SerializableString getEscapeSequence(int aCh) { switch (aCh) { case '\u2028': return new SerializedString("\\u2028"); case '\u2029': return new SerializedString("\\u2029"); default: return null; } }
public ObjectFieldJsonExtractor(String fieldName, JsonExtractor<? extends T> delegate, boolean exceptionOnOutOfBounds) { this.fieldName = new SerializedString(requireNonNull(fieldName, "fieldName is null")); this.delegate = requireNonNull(delegate, "delegate is null"); this.exceptionOnOutOfBounds = exceptionOnOutOfBounds; this.index = tryParseInt(fieldName, -1); }
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType) { if (_serializeAsIndex(paramSerializerProvider)) return createSchemaNode("integer", true); ObjectNode localObjectNode = createSchemaNode("string", true); if ((paramType != null) && (paramSerializerProvider.constructType(paramType).isEnumType())) { ArrayNode localArrayNode = localObjectNode.putArray("enum"); Iterator localIterator = this._values.values().iterator(); while (localIterator.hasNext()) localArrayNode.add(((SerializedString)localIterator.next()).getValue()); } return localObjectNode; }
public BeanPropertyWriter(BeanPropertyDefinition paramBeanPropertyDefinition, AnnotatedMember paramAnnotatedMember, Annotations paramAnnotations, JavaType paramJavaType1, JsonSerializer<?> paramJsonSerializer, TypeSerializer paramTypeSerializer, JavaType paramJavaType2, boolean paramBoolean, Object paramObject) { this._member = paramAnnotatedMember; this._contextAnnotations = paramAnnotations; this._name = new SerializedString(paramBeanPropertyDefinition.getName()); this._wrapperName = paramBeanPropertyDefinition.getWrapperName(); this._declaredType = paramJavaType1; this._serializer = paramJsonSerializer; PropertySerializerMap localPropertySerializerMap; if (paramJsonSerializer == null) localPropertySerializerMap = PropertySerializerMap.emptyMap(); else localPropertySerializerMap = null; this._dynamicSerializers = localPropertySerializerMap; this._typeSerializer = paramTypeSerializer; this._cfgSerializationType = paramJavaType2; this._isRequired = paramBeanPropertyDefinition.isRequired(); if ((paramAnnotatedMember instanceof AnnotatedField)) { this._accessorMethod = null; this._field = ((Field)paramAnnotatedMember.getMember()); } else if ((paramAnnotatedMember instanceof AnnotatedMethod)) { this._accessorMethod = ((Method)paramAnnotatedMember.getMember()); this._field = null; } else { throw new IllegalArgumentException("Can not pass member of type " + paramAnnotatedMember.getClass().getName()); } this._suppressNulls = paramBoolean; this._suppressableValue = paramObject; this._includeInViews = paramBeanPropertyDefinition.findViews(); this._nullSerializer = null; }
public BeanPropertyWriter rename(NameTransformer paramNameTransformer) { String str = paramNameTransformer.transform(this._name.getValue()); if (str.equals(this._name.toString())) return this; return new BeanPropertyWriter(this, new SerializedString(str)); }
public final void writeAsField(JsonGenerator paramJsonGenerator, SerializerProvider paramSerializerProvider, ObjectIdWriter paramObjectIdWriter) { SerializedString localSerializedString = paramObjectIdWriter.propertyName; this.idWritten = true; if (localSerializedString != null) { paramJsonGenerator.writeFieldName(localSerializedString); paramObjectIdWriter.serializer.serialize(this.id, paramJsonGenerator, paramSerializerProvider); } }
protected ObjectIdWriter(JavaType paramJavaType, SerializedString paramSerializedString, ObjectIdGenerator<?> paramObjectIdGenerator, JsonSerializer<?> paramJsonSerializer, boolean paramBoolean) { this.idType = paramJavaType; this.propertyName = paramSerializedString; this.generator = paramObjectIdGenerator; this.serializer = paramJsonSerializer; this.alwaysAsId = paramBoolean; }
public SerializedString findRootName(Class<?> paramClass, MapperConfig<?> paramMapperConfig) { try { ClassKey localClassKey = new ClassKey(paramClass); if (this._rootNames == null) { this._rootNames = new LRUMap(20, 200); } else { SerializedString localSerializedString1 = (SerializedString)this._rootNames.get(localClassKey); if (localSerializedString1 != null) return localSerializedString1; } BeanDescription localBeanDescription = paramMapperConfig.introspectClassAnnotations(paramClass); PropertyName localPropertyName = paramMapperConfig.getAnnotationIntrospector().findRootName(localBeanDescription.getClassInfo()); String str; if ((localPropertyName == null) || (!localPropertyName.hasSimpleName())) str = paramClass.getSimpleName(); else str = localPropertyName.getSimpleName(); SerializedString localSerializedString2 = new SerializedString(str); this._rootNames.put(localClassKey, localSerializedString2); return localSerializedString2; } finally { } }
public BeanPropertyWriter(int typeId, String n, Field f, Method getter) { this.typeId = typeId; name = new SerializedString(n); _field = f; if ((getter == null) && (f == null)) { throw new IllegalArgumentException("Missing getter and field"); } _getter = getter; }
protected Object _unwrapAndDeserialize(JsonParser jp, DeserializationContext ctxt, JavaType rootType, JsonDeserializer<Object> deser) throws IOException, JsonParseException, JsonMappingException { String expName = _config.getRootName(); if (expName == null) { SerializedString sstr = _rootNames.findRootName(rootType, _config); expName = sstr.getValue(); } if (jp.getCurrentToken() != JsonToken.START_OBJECT) { throw JsonMappingException.from(jp, "Current token not START_OBJECT (needed to unwrap root name '" +expName+"'), but "+jp.getCurrentToken()); } if (jp.nextToken() != JsonToken.FIELD_NAME) { throw JsonMappingException.from(jp, "Current token not FIELD_NAME (to contain expected root name '" +expName+"'), but "+jp.getCurrentToken()); } String actualName = jp.getCurrentName(); if (!expName.equals(actualName)) { throw JsonMappingException.from(jp, "Root name '"+actualName+"' does not match expected ('" +expName+"') for type "+rootType); } // ok, then move to value itself.... jp.nextToken(); Object result; if (_valueToUpdate == null) { result = deser.deserialize(jp, ctxt); } else { deser.deserialize(jp, ctxt, _valueToUpdate); result = _valueToUpdate; } // and last, verify that we now get matching END_OBJECT if (jp.nextToken() != JsonToken.END_OBJECT) { throw JsonMappingException.from(jp, "Current token not END_OBJECT (to match wrapper object with root name '" +expName+"'), but "+jp.getCurrentToken()); } return result; }
@SuppressWarnings("unchecked") public BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, Object suppressableValue) { _member = member; _contextAnnotations = contextAnnotations; _name = new SerializedString(propDef.getName()); _declaredType = declaredType; _serializer = (JsonSerializer<Object>) ser; _dynamicSerializers = (ser == null) ? PropertySerializerMap.emptyMap() : null; _typeSerializer = typeSer; _cfgSerializationType = serType; if (member instanceof AnnotatedField) { _accessorMethod = null; _field = (Field) member.getMember(); } else if (member instanceof AnnotatedMethod) { _accessorMethod = (Method) member.getMember(); _field = null; } else { throw new IllegalArgumentException("Can not pass member of type "+member.getClass().getName()); } _suppressNulls = suppressNulls; _suppressableValue = suppressableValue; _includeInViews = propDef.findViews(); // this will be resolved later on, unless nulls are to be suppressed _nullSerializer = null; }