flexjson.JSONSerializer.deepSerialize()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中flexjson.JSONSerializer.deepSerialize()方法的一些代码示例,展示了JSONSerializer.deepSerialize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONSerializer.deepSerialize()方法的具体详情如下:
包路径:flexjson.JSONSerializer
类名称:JSONSerializer
方法名:deepSerialize

JSONSerializer.deepSerialize介绍

[英]This performs a deep serialization of the target instance. It will include all collections, maps, and arrays by default so includes are ignored except if you want to include something being excluded by an annotation. Excludes are honored. However, cycles in the target's graph are NOT followed. This means some members won't be included in the JSON if they would create a cycle. Rather than throwing an exception the cycle creating members are simply not followed. This uses a StringBuilder to output JSON to.
[中]这将对目标实例执行深度序列化。默认情况下,它将包含所有集合、映射和数组,因此除非您希望包含注释排除的内容,否则将忽略包含。我很荣幸。但是,不遵循目标图形中的循环。这意味着,如果一些成员要创建一个循环,那么它们就不会包含在JSON中。创建成员的循环没有抛出异常,只是没有遵循。这将使用StringBuilder将JSON输出到。

代码示例

代码示例来源:origin: magro/memcached-session-manager

@Override
public byte[] serializeAttributes(final MemcachedBackupSession sessions, final ConcurrentMap<String, Object> attributes) {
  if (attributes == null) {
    throw new NullPointerException();
  }
  final ByteArrayOutputStream bos = new ByteArrayOutputStream();
  try {
    // This performs a deep serialization of the target instance.
    // It's serialized to a string as flexjson doesn't like writing to
    // an OutputStreamWriter: it throws the exception "Stepping back two steps is not supported".
    // See https://github.com/moresandeep/memcached-session-manager/commit/db2faaa0a846e16d65ac0b14819689c67bf92c68#commitcomment-512505
    final String serResult = serializer.deepSerialize(attributes);
    if (LOG.isDebugEnabled()) {
      LOG.debug("JSON Serialised object: " + serResult);
    }
    return serResult.getBytes(); // converts to bytes
  } catch (final Exception e) {
    LOG.warn("Caught Exception deserializing JSON " + e);
    throw new IllegalArgumentException();
  } finally {
    close(bos);
  }
}

代码示例来源:origin: dragome/dragome-sdk

public String serialize(Object object)
{
  return jsonSerializer.deepSerialize(object);
}

代码示例来源:origin: pentaho/marketplace

protected String encodeToJSON() {
 JSONSerializer serializer = new JSONSerializer();
 return serializer.deepSerialize( this );
}

代码示例来源:origin: pentaho/data-access

@Override
public void writeTo( IDatabaseConnectionList t, Class<?> type, Type genericType, Annotation[] annotations,
           MediaType mediaType,
           MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream )
 throws IOException, WebApplicationException {
 OutputStreamWriter outputStreamWriter = new OutputStreamWriter( entityStream );
 try {
  new JSONSerializer().exclude( "*.class" ).deepSerialize( t, outputStreamWriter );
 } finally {
  outputStreamWriter.close();
 }
}

代码示例来源:origin: pentaho/data-access

@Override
public void writeTo( IDatabaseTypesList t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
           MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream ) throws IOException, WebApplicationException {
 OutputStreamWriter outputStreamWriter = new OutputStreamWriter( entityStream );
 try {
  new JSONSerializer().exclude( "*.class" ).deepSerialize( t, outputStreamWriter );
 } finally {
  outputStreamWriter.close();
 }
}

代码示例来源:origin: pentaho/data-access

/**
 * Returns a JSON list of the available business models
 *
 * @param domainName optional domain to limit the results
 * @return JSON string of list of ModelInfo objects representing the available models
 * @throws IOException
 */
public String listBusinessModelsJson( String domainName ) throws IOException {
 ModelInfo[] models = listBusinessModels( domainName );
 JSONSerializer serializer = new JSONSerializer();
 String json = serializer.deepSerialize( models );
 return json;
}

代码示例来源:origin: pentaho/data-access

/**
 * Returns a JSON Model object for the requested model. The model will include the basic metadata - categories and
 * columns.
 *
 * @param domainId
 * @param modelId
 * @return JSON string of the model
 */
public String loadModelJson( String domainId, String modelId ) {
 Model model = loadModel( domainId, modelId );
 JSONSerializer serializer = new JSONSerializer();
 String json = serializer.deepSerialize( model );
 return json;
}

代码示例来源:origin: pentaho/data-access

/**
 * Executes a XML query and returns a JSON serialization of the result set
 *
 * @param rowLimit
 * @return
 */
public String doXmlQueryToJson( String xml, int rowLimit ) {
 MarshallableResultSet resultSet = doXmlQuery( xml, rowLimit );
 if ( resultSet == null ) {
  return null;
 }
 JSONSerializer serializer = new JSONSerializer();
 String json = serializer.deepSerialize( resultSet );
 return json;
}

代码示例来源:origin: fabienrenaud/java-json-benchmark

@Benchmark
@Override
public Object flexjson() {
  StringBuilder b = JsonUtils.stringBuilder();
  JSON_SOURCE().provider().flexjsonSer().exclude("*.class").deepSerialize(JSON_SOURCE().nextPojo(), b);
  return b;
}

相关文章