Mapping YAML zu einer Klasse in einem importierten ProjektJava

Java-Forum
Anonymous
 Mapping YAML zu einer Klasse in einem importierten Projekt

Post by Anonymous »

Ich habe ein Projekt, das eine Datenklasse und Funktionalität enthält, um diese Daten zu betreiben. Dieses Projekt enthält eine YAML -Datei.
@Configuration
@EnableConfigurationProperties
//@ConfigurationProperties(prefix = "data")
@ConfigurationProperties
public class DataModel {

private String journey;
private List endpoints = new ArrayList();

public String getJourney() {
return journey;
}

public void setJourney(String journey) {
this.journey = journey;
}

public List getEndpoints() {
return endpoints;
}

public void setEndpoints(List endpoints) {
this.endpoints = endpoints;
}

@Override
public String toString() {
return "DataModel [journey=" + journey + "]";
}
}
< /code>
@Service
public class DataService {

@Autowired
private DataModel datamodel;

public void PrintData() {
System.out.println(datamodel.getJourney());
for(Endpoint endpoint: datamodel.getEndpoints()) {
System.out.println(endpoint.toString());
}
}
}
< /code>
And in project B I have the yaml file.
---
journey: journey1
endpoints:
-
endpointURL: endpoint1
payload: xml
additionalPath: GET
-
endpointURL: endpoint2
payload: json
additionalPath: PUT
-
endpointURL: endpoint3
payload: json
additionalPath: POST
< /code>
Next week, I will try this , but I just want to check, this should work.
You can use a YAML file to populate an imported class.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post