Extend/Inherit java class - how to?

I have a repo with some kind of config in the style of a YAML file... As an example its something like this:
something:
calling-birds: four
french-hens: 3
golden-rings: 5
partridges:
count: 1
location: "a pear tree"
turtle-doves: two
something:
calling-birds: four
french-hens: 3
golden-rings: 5
partridges:
count: 1
location: "a pear tree"
turtle-doves: two
I wanted to extend it to deal with different system:
something:
system: AfricanBirds
calling-birds: four
french-hens: 3
golden-rings: 5
partridges:
count: 1
location: "a pear tree"
turtle-doves: two
system: EuropeanBirds
calling-birds: five
french-hens: 2
golden-rings: 3
partridges:
count: 2
location: "an oak tree"
turtle-doves: one

something:
system: AfricanBirds
calling-birds: four
french-hens: 3
golden-rings: 5
partridges:
count: 1
location: "a pear tree"
turtle-doves: two
system: EuropeanBirds
calling-birds: five
french-hens: 2
golden-rings: 3
partridges:
count: 2
location: "an oak tree"
turtle-doves: one

Its just an example, doesn't make sense necessarily. Now in Java, in another repo, I want to account for this indentation/nested change...
class BirdProperty {
String calling-birds;
Integer french-hens;
List[] partridges;
//...etc
}
class BirdProperty {
String calling-birds;
Integer french-hens;
List[] partridges;
//...etc
}
How do I correct myself now? A lot of code and test use BirdProperty, but now theres two "systems" of them and I need to somehow also indent/nest my java code with some inheritentance or something. Keep in mind the above Java and YAML code is probably wrong in itself, but this is sort of what the code and yaml change was from memory.
4 Replies
JavaBot
JavaBot2w ago
This post has been reserved for your question.
Hey @Steadhaven! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Steadhaven
SteadhavenOP2w ago
Or another example
theUrls:
system: INTERESTS
ntseUrl: some-INTERESTS-website.dev.com
publicApi: some-INTERESTS-api.dev.com
...
system: INVEST
ntseUrl: some-INVEST-website.dev.com
publicApi: some-INVEST-api.dev.com
...
theUrls:
system: INTERESTS
ntseUrl: some-INTERESTS-website.dev.com
publicApi: some-INTERESTS-api.dev.com
...
system: INVEST
ntseUrl: some-INVEST-website.dev.com
publicApi: some-INVEST-api.dev.com
...
The above is the new addition. Before it was only something like:
theUrls:
ntseUrl: some-INTERESTS-website.dev.com
publicApi: some-INTERESTS-api.dev.com
...
theUrls:
ntseUrl: some-INTERESTS-website.dev.com
publicApi: some-INTERESTS-api.dev.com
...
Adding the system property at top level, allows the yaml config repo to have different values for each system. Then in my java code, I can call the correct system to setup my website with the correct stuff in it.
class theUrls {
String ntseUrl;
String publicApi;
}
class theUrls {
String ntseUrl;
String publicApi;
}
What do I do with this java code, now that it is indented/nested inside "system" in the YAML file.
ayylmao123xdd
ayylmao123xdd2w ago
wazaaaaaaaaaaaaaaaaaaap so if you wanna grab the properties you can use the let me grab it
@ConfigurationProperties(prefix = "prefixhere")
@ConfigurationProperties(prefix = "prefixhere")
annotation on your classes however with your example i would swap it to
theUrls:
interests:
ntseUrl: some-INTERESTS-website.dev.com
publicApi: some-INTERESTS-api.dev.com
...
invest:
ntseUrl: some-INVEST-website.dev.com
publicApi: some-INVEST-api.dev.com
...
theUrls:
interests:
ntseUrl: some-INTERESTS-website.dev.com
publicApi: some-INTERESTS-api.dev.com
...
invest:
ntseUrl: some-INVEST-website.dev.com
publicApi: some-INVEST-api.dev.com
...
something like this if you want that or you could do it how you want it with a dependency that lets you scan the yaml file i think jackson can let you read yaml in a method or wherever you want
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?