在java中使用映射序列化Json-更改输出

在java中使用映射序列化Json-更改输出,java,arrays,json,dictionary,Java,Arrays,Json,Dictionary,我有一个返回json的方法 public Map<String,Object> findAllById(Integer id,Integer channelId){ Object[] electronicBill=null; try{ electronicBill =(Object[])ElectronicBillRepository.findAllById(id); electronicBill=(Object[]) electronicBill[0]; St

我有一个返回json的方法

  public Map<String,Object> findAllById(Integer id,Integer channelId){


 Object[] electronicBill=null;


try{    
electronicBill =(Object[])ElectronicBillRepository.findAllById(id);
electronicBill=(Object[]) electronicBill[0];
String clave = null;
Date fecha = null ; 
BigInteger numIdentificacion ;
Integer tipoidentificacion ; 

clave=(String) electronicBill[0];
fecha=(Date) electronicBill[1];
numIdentificacion= (BigInteger) electronicBill[2];
tipoidentificacion=(Integer) electronicBill[3];



 proofXML.put("clave", clave);
 proofXML.put("fecha", fecha);
 proofXML.put("tipoIdentificacion", numIdentificacion);
 proofXML.put("numeroIdentificacion", tipoidentificacion);

}catch(Exception e){
    throw new RuntimeException();
}
return proofXML;
}
现在,我的查询与之相关,我想用以下方式显示输出

  {
    "clave": "50601011600310112345600100010100000000011999999999",
    "fecha": "2016-01-01T00:00:00-0600",
    "emisor": {
    "tipoIdentificacion": "02",
     "numeroIdentificacion": "402260222"
  },

   "comprobanteXml": " "
  }

任何与此相关的帮助,请提前感谢

您可以这样做:

  Map<String, Object> main = new LinkedHashMap<>();
    Map<String, Object> sub = new LinkedHashMap<>();
    sub.put("tipoIdentificacion", "02");
    sub.put("numeroIdentificacion", "402260222");

    main.put("clave", "50601011600310112345600100010100000000011999999999");
    main.put("fecha", "2016-01-01T00:00:00-0600");
    main.put("emisor" , sub);
    main.put("comprobanteXml", "test");
Map main=newlinkedhashmap();
Map sub=新建LinkedHashMap();
子条款(“身份证明”、“02”);
子条款(“数字识别”、“4022260222”);
主要认沽期权(“clave”、“506011160030112345600100010100000000011999999”);
主要投入(“fecha”,“2016-01-01T00:00:00-0600”);
主。put(“emissor”,sub);
put(“comprobanteXml”、“test”);
但也可以看看这里:

  Map<String, Object> main = new LinkedHashMap<>();
    Map<String, Object> sub = new LinkedHashMap<>();
    sub.put("tipoIdentificacion", "02");
    sub.put("numeroIdentificacion", "402260222");

    main.put("clave", "50601011600310112345600100010100000000011999999999");
    main.put("fecha", "2016-01-01T00:00:00-0600");
    main.put("emisor" , sub);
    main.put("comprobanteXml", "test");