简体   繁体   English

Cloud Config服务器响应的Java模型

[英]Java Model for Cloud Config Server Response

I am trying to create a model object for the cloud config server response for me to deserialize the response when I use RestTemplate to call the cloud config server url. 我正在尝试为云配置服务器响应创建模型对象,以便在我使用RestTemplate调用云配置服务器URL时反序列化响应。 When I used few online json to java generators I see the model generated similar to what is shown below. 当我使用很少的在线json到java生成器时,我看到生成的模型类似于下面所示。 However the "source" section is the one which contains all the properties in the form of key value pairs and I want a generic way to deserialize them. 但是,“源”部分是以键值对的形式包含所有属性的部分,我希望有一种通用的方法来反序列化它们。 When I used the generator , it generated something specific to the property I had in the response? 当我使用生成器时,它生成了特定于响应中的属性的某些内容? How can I make it generic? 如何使它通用?

JSON Data JSON数据

 {
   "name":"config",
   "profiles":[
      "dev"
   ],
   "label":null,
   "version":"b8379c098",
   "state":null,
   "propertySources":[
      {
         "name":"<url>/config-data/config-dev.properties",
         "source":{
            "cloud-switch":"on"
         }
      }
   ]

} }

MyPojo MyPojo

public class MyPojo
{
    private PropertySources[] propertySources;

    private String name;

    private null state;

    private null label;

    private String[] profiles;

    private String version;

    public PropertySources[] getPropertySources ()
    {
        return propertySources;
    }

    public void setPropertySources (PropertySources[] propertySources)
    {
        this.propertySources = propertySources;
    }

    public String getName ()
    {
        return name;
    }

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

    public null getState ()
    {
        return state;
    }

    public void setState (null state)
    {
        this.state = state;
    }

    public null getLabel ()
    {
        return label;
    }

    public void setLabel (null label)
    {
        this.label = label;
    }

    public String[] getProfiles ()
    {
        return profiles;
    }

    public void setProfiles (String[] profiles)
    {
        this.profiles = profiles;
    }

    public String getVersion ()
    {
        return version;
    }

    public void setVersion (String version)
    {
        this.version = version;
    }

    @Override
    public String toString()
    {
        return "ClassPojo [propertySources = "+propertySources+", name = "+name+", state = "+state+", label = "+label+", profiles = "+profiles+", version = "+version+"]";
    }
}

PropertySources PropertySources

public class PropertySources
{
    private Source source;

    private String name;

    public Source getSource ()
    {
        return source;
    }

    public void setSource (Source source)
    {
        this.source = source;
    }

    public String getName ()
    {
        return name;
    }

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

    @Override
    public String toString()
    {
        return "ClassPojo [source = "+source+", name = "+name+"]";
    }
}

Source 资源

public class Source
{
    private String cloud-switch;

    public String getCloud-switch ()
    {
        return cloud-switch;
    }

    public void setCloud-switch (String cloud-switch)
    {
        this.cloud-switch = cloud-switch;
    }

    @Override
    public String toString()
    {
        return "ClassPojo [cloud-switch = "+cloud-switch+"]";
    }
}

Making source variable a Map , resolved the issue. 将源变量设为Map,解决了该问题。

public class PropertySource {
    private String name;

    public String getName() { return this.name; }

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

    private Map<String, String> source;

    public Map<String, String> getSource() {
        return source;
    }

    public void setSource(Map<String, String> source) {
        this.source = source;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java - 如何在java spring中将propertysource设置为从云配置服务器获取的配置文件? - How to set propertysource to config file fetched from cloud config server in java spring? 从 Java Spring Cloud Config Server 使用 Python 访问配置属性 - Access Config Properties w/ Python from Java Spring Cloud Config Server 带有配置服务器的 Spring Cloud Eureka - Spring Cloud Eureka with Config Server 简单的 Spring Cloud 配置服务器未启动-java.lang.ClassNotFoundException: ConfigDataMissingEnvironmentPostProcessor - Simple Spring Cloud config server is not starting up-java.lang.ClassNotFoundException: ConfigDataMissingEnvironmentPostProcessor 使用Java而不是bootstrap.yml通过Eureka查找Spring Cloud Config Server - Spring Cloud Config Server lookup through Eureka using Java instead of bootstrap.yml 云服务器中的Java服务器套接字 - java server socket in cloud server Spring Cloud Config服务器显示invalidPrivateKey - Spring Cloud Config server showing invalidPrivateKey 带有 Azure KeyVault 后端的 Spring Cloud Config Server - Spring Cloud Config Server with Azure KeyVault backend Spring 云配置服务器启动失败 - Spring Cloud config server fails to start 自定义 DiscoveryClient 用于发现 Spring 云配置服务器 - Custom DiscoveryClient for to discover Spring Cloud Config server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM