private JSONToPdxMapper getPdxInstance(JsonParser jp, states currentState,
      JSONToPdxMapper currentPdxInstance, String... identityFields) throws IOException {
    String currentFieldName = null;
    if (currentState == states.OBJECT_START && currentPdxInstance == null) {
      currentPdxInstance = createJSONToPdxMapper(null, null, identityFields);// from getlist
    }
    while (true) {
      JsonToken nt = jp.nextToken();

      if (nt == null) {
        return currentPdxInstance;
      }
      switch (nt) {
        case START_OBJECT: {
          objectStarts(currentState);
          currentState = states.OBJECT_START;
          // need to create new PdxInstance
          // root object will not name, so create classname lazily from all members.
          // child object will have name; but create this as well lazily from all members
          JSONToPdxMapper tmp =
              createJSONToPdxMapper(currentFieldName, currentPdxInstance, identityFields);
          currentPdxInstance = tmp;
          break;
        }
        case END_OBJECT: {
          // pdxinstnce ends
          objectEnds(currentState);
          currentState = states.OBJECT_ENDS;
          currentPdxInstance.endObjectField("endobject");
          if (currentPdxInstance.getParent() == null) {
            return currentPdxInstance;// inner pdxinstance in list
          }
          JSONToPdxMapper tmp = currentPdxInstance;
          currentPdxInstance = currentPdxInstance.getParent();
          currentPdxInstance.addObjectField(tmp.getPdxFieldName(), tmp.getPdxInstance());
          break;
        }
        case FIELD_NAME: {
          fieldFound(currentState);
          // field name(object name, value may be object, string, array number etc)
          if (currentState == states.OBJECT_START) {
            currentPdxInstance.setPdxFieldName(currentFieldName);
          }

          currentFieldName = jp.getText();// not a object name
          currentState = states.FIELD_NAME;
          break;
        }
        case NOT_AVAILABLE: {
          throw new IllegalStateException("NOT_AVAILABLE token found");
          // break;
        }
        case START_ARRAY: {
          // need to create array; fieldname may be there; will it case it not there
          arrayStarts(currentState);
          currentState = states.LIST_FOUND;
          PdxListHelper list = getList(jp, currentState, null);
          currentPdxInstance.addListField(currentFieldName, list);
          currentState = states.LIST_ENDS;
          currentFieldName = null;
          break;
        }
        case END_ARRAY: {
          // array is end
          throw new IllegalStateException(
              "END_ARRAY token found in getPdxInstance while current state is " + currentState);
        }
        case VALUE_EMBEDDED_OBJECT: {
          throw new IllegalStateException(
              "VALUE_EMBEDDED_OBJECT token found in getPdxInstance while current state is "
                  + currentState);
        }
        case VALUE_FALSE: {
          // write boolen
          boolFound(currentState);
          currentState = states.SCALAR_FOUND;
          currentPdxInstance.addBooleanField(currentFieldName, jp.getValueAsBoolean());
          currentFieldName = null;
          break;
        }
        case VALUE_NULL: {
          // write null
          nullFound(currentState);
          currentState = states.SCALAR_FOUND;
          currentPdxInstance.addNullField(currentFieldName);
          currentFieldName = null;
          break;
        }
        case VALUE_NUMBER_FLOAT: {
          // write double/float
          doubleFound(currentState);
          currentState = states.SCALAR_FOUND;
          // currentPdxInstance.addDoubleField(currentFieldName, jp.getDoubleValue());
          setNumberField(jp, currentPdxInstance, currentFieldName);
          currentFieldName = null;
          break;
        }
        case VALUE_NUMBER_INT: {
          // write int
          intFound(currentState);
          currentState = states.SCALAR_FOUND;
          // currentPdxInstance.addIntField(currentFieldName, jp.getIntValue());
          setNumberField(jp, currentPdxInstance, currentFieldName);
          currentFieldName = null;
          break;
        }
        case VALUE_STRING: {
          // write string
          stringFound(currentState);
          currentState = states.SCALAR_FOUND;
          currentPdxInstance.addObjectField(currentFieldName, jp.getText());
          currentFieldName = null;
          break;
        }
        case VALUE_TRUE: {
          // write bool
          boolFound(currentState);
          currentState = states.SCALAR_FOUND;
          currentPdxInstance.addBooleanField(currentFieldName, jp.getValueAsBoolean());
          currentFieldName = null;
          break;
        }
        default: {
          throw new IllegalStateException("Token not handled " + nt);
        }
      }
    }
  }
Converts a PdxInstance into a JSON document in byte-array form

@param pdxInstance The PdxInstance to convert
@return the JSON byte array
@throws JSONFormatterException if unable to create the JSON document
geode-core/src/main/java/org/apache/geode/pdx/JSONFormatter.java