using String to represent date

hey guys. i want to have a method that accepts fromDate and toDate args. and then later in this method i will concat the args to the string:
"<FrDt>"+fromDate+"</FrDt>\n" +
"<ToDt>"+toDate+"</ToDt>\n"
"<FrDt>"+fromDate+"</FrDt>\n" +
"<ToDt>"+toDate+"</ToDt>\n"
can i just use String datatype on the parameters? bc using any date datatype doesnt make sense. thx
61 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @bambyzas! 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 closed 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.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
but why cant i just use strings?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
ok, now its clear but where do i start then? bc theres too much things going on. LocalDate, Date, DateFormatter, and so on
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
but i have another question
public void method1(){
//some stuff
getTransactionsByIbanAndDate(iban,???,???);
//other stuff
}

public void getTransactionsByIbanAndDate(String iban, ???, ???){
//concat args to string
}
public void method1(){
//some stuff
getTransactionsByIbanAndDate(iban,???,???);
//other stuff
}

public void getTransactionsByIbanAndDate(String iban, ???, ???){
//concat args to string
}
i just my dates to be in 2020-12-12 format. i dont need time, GMT appended, etc can i use smth like this?: LocalDate date = LocalDate.of(2020, 1, 8);
tjoener
tjoener6mo ago
yes https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html This page has a good overview on all the "new" date and time types
bambyzas
bambyzasOP6mo ago
and then i can do date.toString() and append it to other Strings?
tjoener
tjoener6mo ago
sure, but then you will use the default formatting But if that's ok, that's ok And also don't write out your xml by doing string concatenations, but use the actual XML DOMDocument etc java provides
bambyzas
bambyzasOP6mo ago
you mean this formatting? 2020-01-08? bc thats what i need
tjoener
tjoener6mo ago
Or even better, spring can automatically generate those for you just like it does json Yes Just remember, if they ever decide to change the formatting, your application will break
bambyzas
bambyzasOP6mo ago
can you elaborate? rn i have this
No description
tjoener
tjoener6mo ago
Baeldung
Using XML in @RequestBody in Spring REST | Baeldung
Learn how to leverage Jackson XML to use XML within Spring REST.
bambyzas
bambyzasOP6mo ago
sorry, i dont know what to do with this article. it doesnt provide me any info
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
so again what is the problem with my method?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
and what are the alternatives?
tjoener
tjoener6mo ago
requestbody xml, and have jackson write the xml for you
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener6mo ago
Based on objects google json doesn't support xml
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener6mo ago
The baeldung article is fairly complete though you need jackson-dataformat-xml You make an object containing what you want your xml to look like With the same annotations as used for json basically
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener6mo ago
yeah fine, but that's not spring boot related He's working in a spring boot app where you don't need to do any of this manual stuff
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
i have two methods in my service. one getCurrentTransactions accepts String requestBody that comes from the controller (controller accepts xml body). but i need to have another method in my service getCurrentTransactionsByIbanAndDate and i need to append dates and iban to the xml body. and idk how to do it. thats why i have xml as a string
tjoener
tjoener6mo ago
"getCurrentTransactions accepts String requestBody" An actual string? or json or xml?
bambyzas
bambyzasOP6mo ago
@GetMapping(value = "/transactions", consumes = "application/xml", produces = "application/xml")
public String getCurrentTransactions(@RequestBody String requestBody) throws JAXBException, IOException {
return bgwService.getCurrentSwedbankTransactions(requestBody);
}
@GetMapping(value = "/transactions", consumes = "application/xml", produces = "application/xml")
public String getCurrentTransactions(@RequestBody String requestBody) throws JAXBException, IOException {
return bgwService.getCurrentSwedbankTransactions(requestBody);
}
and service method looks like this:
public String getCurrentTransactions(String requestBody) {
log.info("BGWService.getCurrentTransactions");
sendAccountStatementRequest(requestBody);
//other stuff
public String getCurrentTransactions(String requestBody) {
log.info("BGWService.getCurrentTransactions");
sendAccountStatementRequest(requestBody);
//other stuff
tjoener
tjoener6mo ago
sendAccountStatementRequest is an external api?
bambyzas
bambyzasOP6mo ago
yes
tjoener
tjoener6mo ago
that's just passing it through, which is... not the best solution but fine for now I guess And the other method you have to modify the xml for?
bambyzas
bambyzasOP6mo ago
thats not what i asked for can smb help me with this?
tjoener
tjoener6mo ago
well, if you only need to append those items parse the requestbody in an xml document And append those two fields
tjoener
tjoener6mo ago
Mkyong.com
How to read XML file in Java - (DOM Parser) - Mkyong.com
This tutorial will show you how to use the Java built-in DOM parser to read an XML file.
bambyzas
bambyzasOP6mo ago
cant parse bc i dont have xml body
tjoener
tjoener6mo ago
but you have the requestbody what else are you appending to?
bambyzas
bambyzasOP6mo ago
i dont ffs
tjoener
tjoener6mo ago
what are you APPENDING to then?
bambyzas
bambyzasOP6mo ago
give me a second ill show u brb
bambyzas
bambyzasOP6mo ago
No description
bambyzas
bambyzasOP6mo ago
when using 2nd controller i cant use getAllTransactions, bc it needs to accept request body, and i dont have it. so i need to create it somewhere. so i created another method in the service, and in its body i have String with xml
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
yeah, but i dont have the xml request body when using 2nd controller :/
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
what? i dont understand ur sentence what is it?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
both service methods should have request bodies in them idk what u asked tbh
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
correct. getAllTransacationsByIbanAndDate method doesnt have the xml request body. thats why i have this
No description
bambyzas
bambyzasOP6mo ago
i was thinking that maybe i can extract this xml req body, and just use it everywhere i need. in this method id insert needed values for needed tags
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
no u didnt
No description
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
second controller cant accept xml body. can it still magically generate xml?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
thats not what i need i dont need my contrller to return xml
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
what bc ill be sending that xml to an external api?
JavaBot
JavaBot6mo 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.
Want results from more Discord servers?
Add your server