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:
can i just use String datatype on the parameters? bc using any date datatype doesnt make sense. thx61 Replies
⌛
This post has been reserved for your question.
Hey @bambyzas! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
but why cant i just use strings?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
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•6mo ago
Message Not Public
Sign In & Join Server To View
but i have another question
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);
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
and then i can do
date.toString()
and append it to other Strings?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
you mean this formatting?
2020-01-08
? bc thats what i needOr 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
can you elaborate? rn i have this
Baeldung
Using XML in @RequestBody in Spring REST | Baeldung
Learn how to leverage Jackson XML to use XML within Spring REST.
sorry, i dont know what to do with this article. it doesnt provide me any info
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
so again what is the problem with my method?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
and what are the alternatives?
requestbody xml, and have jackson write the xml for you
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Based on objects
google json doesn't support xml
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
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•6mo ago
Message Not Public
Sign In & Join Server To View
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•6mo ago
Message Not Public
Sign In & Join Server To View
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"getCurrentTransactions accepts String requestBody"
An actual string? or json or xml?
and service method looks like this:
sendAccountStatementRequest is an external api?
yes
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?
thats not what i asked for
can smb help me with this?
well, if you only need to append those items
parse the requestbody in an xml document
And append those two fields
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.
cant parse bc i dont have xml body
but you have the requestbody
what else are you appending to?
i dont
ffs
what are you APPENDING to then?
give me a second
ill show u
brb
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 xmlUnknown User•6mo ago
Message Not Public
Sign In & Join Server To View
yeah, but i dont have the xml request body when using 2nd controller :/
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
what? i dont understand ur sentence
what is
it
?Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
both service methods should have request bodies in them
idk what u asked tbh
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
correct. getAllTransacationsByIbanAndDate method doesnt have the xml request body. thats why i have this
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•6mo ago
Message Not Public
Sign In & Join Server To View
no u didnt
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
second controller cant accept xml body. can it still magically generate xml?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
thats not what i need
i dont need my contrller to return xml
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
what
bc ill be sending that xml to an external api?
💤
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.