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
JavaBot9mo 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 User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
but why cant i just use strings?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
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 User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
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
tjoener9mo 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
i hate SQL so much its unreal
and then i can do date.toString() and append it to other Strings?
tjoener
tjoener9mo 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
i hate SQL so much its unreal
you mean this formatting? 2020-01-08? bc thats what i need
tjoener
tjoener9mo 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
i hate SQL so much its unreal
can you elaborate? rn i have this
No description
tjoener
tjoener9mo ago
Baeldung
Using XML in @RequestBody in Spring REST | Baeldung
Learn how to leverage Jackson XML to use XML within Spring REST.
i hate SQL so much its unreal
sorry, i dont know what to do with this article. it doesnt provide me any info
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
so again what is the problem with my method?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
and what are the alternatives?
tjoener
tjoener9mo ago
requestbody xml, and have jackson write the xml for you
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener9mo ago
Based on objects google json doesn't support xml
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener9mo 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 User9mo ago
Message Not Public
Sign In & Join Server To View
tjoener
tjoener9mo 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 User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
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
tjoener9mo ago
"getCurrentTransactions accepts String requestBody" An actual string? or json or xml?
i hate SQL so much its unreal
@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
tjoener9mo ago
sendAccountStatementRequest is an external api?
tjoener
tjoener9mo 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?
i hate SQL so much its unreal
thats not what i asked for can smb help me with this?
tjoener
tjoener9mo ago
well, if you only need to append those items parse the requestbody in an xml document And append those two fields
tjoener
tjoener9mo 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.
i hate SQL so much its unreal
cant parse bc i dont have xml body
tjoener
tjoener9mo ago
but you have the requestbody what else are you appending to?
i hate SQL so much its unreal
i dont ffs
tjoener
tjoener9mo ago
what are you APPENDING to then?
i hate SQL so much its unreal
give me a second ill show u brb
i hate SQL so much its unreal
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 User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
yeah, but i dont have the xml request body when using 2nd controller :/
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
what? i dont understand ur sentence what is it?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
both service methods should have request bodies in them idk what u asked tbh
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
correct. getAllTransacationsByIbanAndDate method doesnt have the xml request body. thats why i have this
No description
i hate SQL so much its unreal
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 User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
no u didnt
No description
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
second controller cant accept xml body. can it still magically generate xml?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
thats not what i need i dont need my contrller to return xml
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
i hate SQL so much its unreal
what bc ill be sending that xml to an external api?
JavaBot
JavaBot9mo 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?