Comments (12)
- Issue Imported From: https://github.com/jersey/jersey/issues/287
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @mpotociar
- Original Issue Closed By:@glassfishrobot
from jersey.
@glassfishrobot Commented
Reported by [email protected]
from jersey.
@glassfishrobot Commented
[email protected] said:
As i understand things java.util.Date or joda-time DateTime require a data
formatting class to parse the date as a String. How do you propose to inform the
runtime of the date formatter to use?
Specifying an annotation for date formatting to use seems a bit over the top
Do you have any examples of classes that would be tricky to use?
from jersey.
@glassfishrobot Commented
[email protected] said:
s/any examples/any other examples
from jersey.
@glassfishrobot Commented
[email protected] said:
Apologies, maybe I haven't explained myself properly. I have to confess that I
have few examples currently, but suspect this is a need that can be encountered
frequently (unless I'm missing something?).
Date indeed needs a formatter, but then I never really liked Date.
joda-time DateTime is better in that it will attempt to format from an object
passed into its constructor. It will usually handle most wellknown date formats,
e.g. ISO8601. This would work fine with Jersey apart from that Jersey looks for
a String constructor and so passes over the Object constructor of the DateTime
class.
I wouldn't expect any special handling of date formats, or even an annotation.
My point was that there may be a case of extending the search criteria when
trying to find a way of creating an object from a parameter. Currently this is
valueOf and a String constructor. It could be argued that an Object constructor
could be looked for as well.
Alternatively, perhaps an extra element can be added to the QueryParam
annotation to specify a method name to call in order to create the expected
object? If I have an object of type Example, with a static method that parses
from a String called createFromString, this could result in a declaration such as:
@QueryParam("example", "createFromString") Example example
Apologies - suspect my annotation syntax is wrong...! hopefully you get the gist.
The workaround I am doing at the moment is to pass the params as strings and
then create the DateTime objects from them inside the resource. Having to avoid
this step would be more...cool. Hopefully I'm not being too nit-picky with this one.
Another example class is the json-lib JSONObject class which has neither a
String constructor nor a valueOf(String) method. It uses fromObject(Object),
which can be used to pass in a JSON string to parse.
from jersey.
@glassfishrobot Commented
[email protected] said:
Thanks for the additional information, i understand things better now.
How about i modify the MultivaluedDefaultStringConstructorExtractor class to
support a constructor that takes an Object parameter and the runtime assumes
that it can pass the String instance as the parameter? Would that work for you?
We could also have a general rule to search for static method of the type:
T (String x)
T (Object x)
from jersey.
@glassfishrobot Commented
[email protected] said:
-
-
- Issue 26 has been marked as a duplicate of this issue. ***
-
from jersey.
@glassfishrobot Commented
[email protected] said:
See also the dup issue 15
from jersey.
@glassfishrobot Commented
[email protected] said:
In the latest 0.8 builds developers may now add support for their own types.
For example one can write a injectable provider for @QueryParam using joda-time
DateTime:
@Provider
public JodaDateTimeProvider implements
InjectableProvider<QueryParam, Parameter, PerRequestInjectable {
public PerRequestInjectable getInjectable(InjectableContext ic,
QueryParam a, Parameter c) {
if (!DateTime.isAssignableFrom(c.getParameterClass())
return null;
final String name = c.getSourceName();
return new PerRequestInjectable() {
public DateTime getValue(HttpContext c)
{ String value = c.getUriInfo().getQueryParameters().getFirst(name); DateTime d = ... return d; }
};
}
}
from jersey.
@glassfishrobot Commented
Was assigned to jersey-issues
from jersey.
@glassfishrobot Commented
This issue was imported from java.net JIRA JERSEY-15
from jersey.
@glassfishrobot Commented
Marked as fixed on Thursday, May 22nd 2008, 10:58:41 pm
from jersey.
Related Issues (20)
- What is the difference between jersey2.x, jersey 3.x and jersey4.x and which one is recommended? HOT 8
- Connection Leak when Circuit Breaker Hystrix Command timeout HOT 2
- 3.1.7 OSGi bundle issue HOT 12
- "MessageBodyWriter not found for media type=application/xml" error preventing upgrade from 2.32 to 2.33 HOT 4
- KeepAlive Caching stops working in 2.41 HOT 1
- Incosistent handling of inherited @Produces annotations HOT 2
- AsyncContext completion attempt after AsyncListener.onError is called HOT 3
- Process dump caused by malicious response headers HOT 2
- ChunkedInput.close is not sufficient to release client connections
- Json Jackon Maven test failing for version 3.1.3 HOT 1
- NPE after switching to jersey-micrometer HOT 8
- Issue when injecting @QueryParam values when the URL query string has percentage encoded &
- JdkConnector using Obsolete `java.net.CookieManager` HOT 2
- `JerseySseEventSource` ignores `onError` callback supplied to `register()` method, making it impossible to surface HTTP/network errors
- Jetty connector is not supported on JDK version less than 17 HOT 7
- RequestEvent for RequestEventListener might lost request attributes for async flow HOT 1
- Add ability to disable DefaultJacksonJaxbJsonProvider
- Jsonb still not injectable
- Jersey 2.X ResourceDoclet much slower compared to 1.X
- Update DigestAuthenticator.java to implement RFC 7616
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jersey.