Giter Site home page Giter Site logo

Comments (12)

jerseyrobot avatar jerseyrobot commented on July 19, 2024

from jersey.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@glassfishrobot Commented
Reported by [email protected]

from jersey.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@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.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@glassfishrobot Commented
[email protected] said:
s/any examples/any other examples

from jersey.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@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.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@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.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@glassfishrobot Commented
[email protected] said:

      • Issue 26 has been marked as a duplicate of this issue. ***

from jersey.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@glassfishrobot Commented
[email protected] said:
See also the dup issue 15

from jersey.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@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.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@glassfishrobot Commented
Was assigned to jersey-issues

from jersey.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@glassfishrobot Commented
This issue was imported from java.net JIRA JERSEY-15

from jersey.

jerseyrobot avatar jerseyrobot commented on July 19, 2024

@glassfishrobot Commented
Marked as fixed on Thursday, May 22nd 2008, 10:58:41 pm

from jersey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.