示例#1
0
 @Override
 public final void writeFieldName(SerializedString name)
     throws IOException, JsonGenerationException {
   // Object is a value, need to verify it's allowed
   int status = _writeContext.writeFieldName(name.getValue());
   if (status == JsonWriteContext.STATUS_EXPECT_VALUE) {
     _reportError("Can not write a field name, expecting a value");
   }
   _writeFieldName(name, (status == JsonWriteContext.STATUS_OK_AFTER_COMMA));
 }
 protected Object _unwrapAndDeserialize(
     JsonParser jp, DeserializationContext ctxt, JavaType rootType, JsonDeserializer<Object> deser)
     throws IOException, JsonParseException, JsonMappingException {
   SerializedString rootName = _provider.findExpectedRootName(ctxt.getConfig(), rootType);
   if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
     throw JsonMappingException.from(
         jp,
         "Current token not START_OBJECT (needed to unwrap root name '"
             + rootName
             + "'), but "
             + jp.getCurrentToken());
   }
   if (jp.nextToken() != JsonToken.FIELD_NAME) {
     throw JsonMappingException.from(
         jp,
         "Current token not FIELD_NAME (to contain expected root name '"
             + rootName
             + "'), but "
             + jp.getCurrentToken());
   }
   String actualName = jp.getCurrentName();
   if (!rootName.getValue().equals(actualName)) {
     throw JsonMappingException.from(
         jp,
         "Root name '"
             + actualName
             + "' does not match expected ('"
             + rootName
             + "') 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 '"
             + rootName
             + "'), but "
             + jp.getCurrentToken());
   }
   return result;
 }
示例#3
0
 /**
  * Non-optimal default implementation for serializing given {@link SerializedString}: sub-classes
  * are strongly recommmended to implement this efficiently. Default implementation mostly exists
  * to avoid introducing binary incompatibility.
  *
  * @since 1.6
  */
 protected void _writeFieldName(SerializedString name, boolean commaBefore)
     throws IOException, JsonGenerationException {
   // Note: sub-classes are strongly urged to override this method
   _writeFieldName(name.getValue(), commaBefore);
 }