首页 > 解决方案 > 评估表达式 json 结果在调试模式下与最终 json 结果不同

问题描述

我有一个这样的控制器:

 @ResponseBody
@RequestMapping(value = "/getLayersOfCategory/{categoryId}", method = RequestMethod.GET)
public LayersResult GetLayersOfCategory(@PathVariable("categoryId") Integer categoryId,@RequestHeader("secret") String secret) {
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm");
    DataServicesModel dataServicesModel=new DataServicesModel();
    LocalDateTime now = LocalDateTime.now();



    CategoriesEntity categoriesEntity=new CategoriesEntity();
    categoriesEntity.setId(categoryId);
    List<Object[]> layersCategoriesEntityList=layersCategoriesRepository.findAllByCategoryId(categoryId);
    List<String> stringList=new ArrayList<>();

    for (Object[] row:layersCategoriesEntityList){
        stringList.add(row[2].toString());
    }
     LayersResult layersResult=this.GetPoints(stringList);
    **** return layersResult;
}

在 ****,当我评估“layersResult”表达式时,它会显示一个像这样的 json:

在此处输入图像描述

但是当我通过邮递员呼叫控制器时,我得到如下信息:

在此处输入图像描述

如您所见, iconUrl 键有所不同。我不知道如果没有任何代码行可以改变最终结果,控制器末尾的结果会发生变化。提前感谢您的回复。

这是一个DataLayerModel:

   package org.rajman.lbs.neshan.business.data.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParseException;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;

import javax.persistence.*;


@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DataLayerModel {
    private Integer id;
    private String title;
    private String type;
    private String iconUrl="kdjjfhskdjfh";
    private String webUrl="http://map.tabr*.ir";
    @JsonIgnore
    public String getStyle() { return style;
    }
    public void setStyle(String style) {
        this.style = style;
    }
    private String style="{\"icon\":\"dt.png\"}";
    @Value("${url.webUrl:#{null}}")
    @JsonIgnore
    public String getWebUrl() {
        return webUrl;
    }
    public void setWebUrl(String webUrl) {
        this.webUrl = webUrl;
    }
    public DataLayerModel() {
    }
    public DataLayerModel(Integer id, String title, String type, String style) {
        this.id = id;
        this.title = title;
        this.type = type.equals("ST_Polygon") || type.equals("polygon") ? "polygon" : "point";
        this.style=style;
        //this.iconUrl = getIconUrl();
    }

    public String getIconUrl() {
        Object icon;
        String url="";
        JSONObject jsonObject;
        try {
            url=this.style;
             jsonObject = new JSONObject(this.style);
            icon=jsonObject.get("icon");
            url=this.getWebUrl()+"/images/"+icon.toString();
        }
        catch (Exception e){
            System.out.println(e);
        }
        return url;
    }
    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}

标签: jsonspring-booturlmodelcontroller

解决方案


假设iconUrl是一个String。即序列化是直截了当的。

我猜唯一会出错的是getIconUrl()方法。

请尝试layers.get(0).getIconUrl()在同一调试点进行评估。


推荐阅读