使用杰克逊弹簧解析对象阵列

时间:2017-03-30 10:06:16

标签: java json spring parsing

我有以下要求

{
  "name":"Ajeesh",
  "description":"hello",
  "platform_settings":[
      {"key":"value"},
      {"key1":"key2"}..  // This key value can be anything upto n times
  ]
}

我为上面创建了一个POJO,如下所示

package com.payunow.socialsharemodule.models;

import com.fasterxml.jackson.databind.ObjectMapper;// in play 2.3
import java.util.List;
import java.util.Map;

public class Share {
    private String name;
    private String description;


    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDescription(String description) {
        this.description = description;
    }


    @Override
    public String toString(){
        return getName() + ", "+getDescription();
    }
}

在将JSON转换为Java对象时,如何定义platform_settings对象数组?

1 个答案:

答案 0 :(得分:5)

您可以将platform_settings声明为地图列表:

"use strict";

const express = require("express");
const api = express.Router();       

    api.get("/HolaBananas", function(req, res){
        res.send("hello bananas!");
    });
module.exports = api;