org.ff4j.core.Feature.toJson()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(92)

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

Feature.toJson介绍

[英]Convert Feature to JSON.
[中]将特性转换为JSON。

代码示例

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public String toStore(Feature bean) {
  if (bean == null) return null;
  return bean.toJson();
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public String toString() {
  return toJson();
}

代码示例来源:origin: ff4j/ff4j

@Override
public JsonElement serialize(Feature feature, Type srcType, JsonSerializationContext context) {
  return gson.fromJson(feature.toJson(), JsonElement.class);
}

代码示例来源:origin: ff4j/ff4j

/**
 * Convert feature array to json.
 *
 * @param features
 *            target features
 * @return json string
 */
public static String featureArrayToJson(Feature[] features) {
  StringBuilder sb = new StringBuilder();
  sb.append("[");
  if (features != null) {
    boolean first = true;
    for (Feature feature : features) {
      sb.append(first ? "" : ",");
      sb.append(feature.toJson());
      first = false;
    }
  }
  sb.append("]");
  return sb.toString();
}

代码示例来源:origin: ff4j/ff4j

if (getFf4j().getFeatureStore().exist(featureId)) {
  Feature f = getFf4j().getFeatureStore().read(featureId);
  res.getWriter().println(f.toJson());
} else {
    sb.append(",");
  sb.append(feature.toJson());
  first = false;

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public JsonDocument toStore(Feature feature)  {
  if (feature == null) return null;
  JsonObject jsonObject;
  try {
    jsonObject = TRANSCODER.stringToJsonObject(feature.toJson());
    jsonObject.put("_class", Feature.class.getCanonicalName());
  } catch (Exception e) {
    throw new FeatureAccessException("Cannot parse the feature", e);
  }
  return JsonDocument.create(feature.getUid(), jsonObject);
}

代码示例来源:origin: ff4j/ff4j

Feature f = getFf4j().getFeatureStore().read(uid);
res.setContentType(CONTENT_TYPE_JSON);
res.getWriter().println(f.toJson());

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public void putFeature(Feature fp) {
  Util.assertNotNull(fp);
  Jedis jedis = null;
  try {
    jedis = getJedis();
    jedis.set(KEY_FEATURE + fp.getUid(), fp.toJson());
    jedis.expire(KEY_FEATURE + fp.getUid(), getTimeToLive());
  } finally {
    if (jedis != null) {
      jedis.close();
    }
  } 
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public void update(Feature fp) {
  Util.assertNotNull("Feature" , fp);
  if (!exist(fp.getUid())) {
    throw new FeatureNotFoundException(fp.getUid());
  }
  Jedis jedis = null;
  try {
    jedis = getJedis();
    jedis.set(KEY_FEATURE + fp.getUid(), fp.toJson());
    jedis.persist(KEY_FEATURE + fp.getUid());
  } finally {
    if (jedis != null) {
      jedis.close();
    }
  }
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public void create(Feature fp) {
  Util.assertNotNull("Feature", fp);
  if (exist(fp.getUid())) {
    throw new FeatureAlreadyExistException(fp.getUid());
  }
  Jedis jedis = null;
  try {
    String id = fp.getUid();
    jedis = getJedis();
    // Store the feature in the mapping bucket.
    jedis.sadd(KEY_FEATURE_MAP, id);
    jedis.set(KEY_FEATURE + id, fp.toJson());
    jedis.persist(KEY_FEATURE + id);
  } finally {
    if (jedis != null) {
      jedis.close();
    }
  }
}

相关文章