代码之家  ›  专栏  ›  技术社区  ›  user5702955

将json转换为java对象(pojo)时,与pojo一起显示的包名称

  •  0
  • user5702955  · 技术社区  · 6 年前

    当我运行这个时,我有下面的代码,不知道为什么包名会跟这个一起出现

    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();
            }
    
    
        }
    }
    
    0 回复  |  直到 6 年前
        1
  •  1
  •   Flaviu    6 年前

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