-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding date field #59
Conversation
val value: String = get(fieldName) as? String ?: return null | ||
return formatter(value) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can simplify as follows:
= (get(fieldName) as? String?).apply { formatter(value) }
(I haven't tested it, just writing it off the top of my head)
import java.util.TimeZone | ||
|
||
/** | ||
* Jackson’s date formatter, pruned to Moshi's needs. Forked from this file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what you mean by "pruned to Moshi's needs"? What does Moshi have to do with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing it. :)
Questions:
|
@cbeust I can remove this component if needed. I just added it to be used on the unit test. This code comes from |
@damphat In my opnion the parse and stringify of the date needs to be done by a external code (like other JSON mappers used to do). The class |
…ate array added and simplification of date mapping
@damphat How do you suggest to implement the |
In java-script world:
As you see java-script use ISO8601 to stringify a date by default.
|
@damphat |
I understand what you said. But I gave the suggestion base on 3 things:
it.date("birthday") // default to iso, keep the code less verbose
it.date("birthday", customFormatter) // provide custom formatter if needed
render(Date()) // this API is already use by many projects, to keep this work we must provide default formatter PS: I'm not sure about my ideas, I think JsonObject.date() is great for json query, keep moving! |
@damphat The default formatter involves the Java class |
@damphat Now the |
You added the concept
|
1: Modulability, it maintains the code more consisce in case of implementation of new modifiers and make the code more reability and less confusing. A single lambda function seems to be enough but adds complexibility. |
@ppamorim Note that you are working with public apis so that is not acceptable. That idea may still a good choice for application, non-public code (implementation code). |
How many times you will repeat saying that I am not working with a application? That's very rude and doesn't improve anything on that conversation. I will not change until @cbeust do a review. |
Sorry @ppamorim, I think you are active and full energy when you contribute to open-source projects. Don't care much about me and my words. Focus more on your job, I think you can learn something and 'make the world a better place'. |
Sorry for the late review. It seems to me this pull request is obsoleted by the latest addition to Klaxon: object binding with custom converters. If I wanted to convert a date, I would simply provide my own converter with the correct expected format before I run the parsing. Should we close this PR? |
Implementing this the developer is able to parse the date using a lambda function. I was think to implement something like this:
We can also provide another artifact just to resolve the
Iso8601Utils
dependency like other libraries used to do. What you think about it?Thank you.