【问题标题】:Package name displayed along with pojo while converting json to java object (pojo)将 json 转换为 java 对象(pojo)时与 pojo 一起显示的包名称
【发布时间】:2019-09-14 10:27:15
【问题描述】:

当我运行这个时,我有下面的代码,不知道为什么包名会随之而来

com.heiler.ppm.fulltextsearch.object.FullTextSearchConfigModel@5c3bd550[indexName=Items_AllSupplierCatalogs_en,indexLabel=Items (All Supplier Catalogs) en,alias=,catalogs=[SupplierCatalog1, SupplierCatalog2],rootEntities=[com.heiler.ppm.fulltextsearch.object.RootEntity@6a41eaa2[entityIdentifier=Article,fields=[com.heiler.ppm.fulltextsearch.object.Field@7cd62f43[name=Article.SupplierAID,type=text,searchable=true,sortable=true,facetable=false,additionalProperties={}]],subEntities=

public class ExportToESMappingCreator {


    public static void main(String[] args) {
         ObjectMapper objectMapper = new ObjectMapper();
         FullTextSearchConfigModel searchConfig= null;
         try {
              searchConfig= objectMapper.readValue(new File("src\\main\\resources\\indexconfig.json"), FullTextSearchConfigModel.class);
            // System.out.println(searchConfig.toString());
            // String json=objectMapper.writeValueAsString(searchConfig);
             System.out.println(searchConfig);
         } catch (JsonParseException e) {

            e.printStackTrace();
        } catch (JsonMappingException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }


    }
}

【问题讨论】:

    标签: java jackson pojo jayway


    【解决方案1】:

    可能 FullTextSearchConfigModel 的 toString() 方法(在您打印对象时被调用)使用 getClass() 来构建对象的字符串表示,它返回完全限定的类名(即包括包名)。见https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 2015-02-17
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多