BannerSerialization.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:NexusInventory 作者:
/**
 * A method to serialize banner meta to a JSONObject. Saves the base color, each pattern color, and each
 * pattern type.
 *
 * @param banner The BannerMeta to serialize
 * @return The JSONObject representation of the BannerMeta, or null if an exception occurred
 */
public static JSONObject serializeBanner(BannerMeta banner) {
    try {
        JSONObject root = new JSONObject();
        if (banner.getBaseColor() != null)
            root.put("base-color", banner.getBaseColor().getDyeData());

        JSONArray colors = new JSONArray();
        JSONArray patternTypes = new JSONArray();
        for (Pattern pattern : banner.getPatterns()) {
            colors.put(pattern.getColor().getDyeData());
            patternTypes.put(pattern.getPattern().getIdentifier());
        }

        root.put("colors", colors);
        root.put("pattern-types", patternTypes);

        return root;
    } catch (JSONException ex) {
        ex.printStackTrace();
        return null;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号