• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Joda LocalTime attribute in ERRest
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Joda LocalTime attribute in ERRest


  • Subject: Re: Joda LocalTime attribute in ERRest
  • From: Paul Hoadley <email@hidden>
  • Date: Tue, 29 Sep 2015 10:27:12 +0930

For the archives:

On 25 Sep 2015, at 8:56 am, Paul Hoadley <email@hidden> wrote:

On 23 Sep 2015, at 10:12 pm, Philippe Rabier <email@hidden> wrote:

You have to modify ERXRestUtils but I’m surprised it’s not already done.

AFAICS, it’s done for LocalDateTime and LocalDate, but not LocalTime (or DateTime).

There are 2 methods:
- convertValue to build the output
- coerceValueToTypeNamed to convert input data

For example, we wanted to support epoch format for NSTimestamp attributes so we modified a little bit ERXRestUtils and ERXRestRequestNode:
https://github.com/Sophiacom/wonder/tree/sophiacom/Frameworks/EOF/ERRest/Sources/er/rest

This part should be refactored because it’s too big. But we moved away from the full ERRest stack so we won’t do it, I think, because we won’t be able to test this modifications in production.

Thanks for the background. I thought that might be where all the magic happens, but I was also hoping someone would tell me there was an extensible way to plug in new types. That would certainly be a nice feature.

I dove into ERXRestUtils with limited (well, no) success—it’s not clear to me how/when these methods are used. Since I only need this working on the output side for now, I extended ERXJSONRestWriter to register a custom JsonValueProcessor class for the LocalTime type:

@Override
protected JsonConfig configWithContext(ERXRestContext context) {
JsonConfig result = super.configWithContext(context);
result.registerJsonValueProcessor(LocalTime.class,
new LocalTimeProcessor(context));
return result;
}

LocalTimeProcessor then implements:

@Override
public Object processArrayValue(Object value, JsonConfig config) {
if (value == null) {
return null;
} else {
DateTimeFormatter fmt = DateTimeFormat.forPattern("HH:mm");
return fmt.print((LocalTime) value);
}
}

@Override
public Object processObjectValue(String key, Object value,
JsonConfig config) {
return processArrayValue(value, config);
}

And I then register the new writer in didFinishLaunching():

ERXRestFormat.registerFormatNamed(new ERXJSONRestParser(),
new LSJSONRestWriter(), new ERXRestFormatDelegate(),
ERXRestFormat.JSON_KEY, "application/json");

Critiques welcome. Here’s one: this only adds the new LocalTime type for JSON output. While this is fine (because (a) I only want JSON, and (b) both XML and plist output already do something sensible with that type), it can’t be an appropriate general way to add new types. Are custom types covered in a WOWODC talk I missed? Pascal?


-- 
Paul Hoadley
http://logicsquad.net/



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Joda LocalTime attribute in ERRest (From: Paul Hoadley <email@hidden>)
 >Re: Joda LocalTime attribute in ERRest (From: Paul Hoadley <email@hidden>)
 >Re: Joda LocalTime attribute in ERRest (From: Philippe Rabier <email@hidden>)
 >Re: Joda LocalTime attribute in ERRest (From: Paul Hoadley <email@hidden>)

  • Prev by Date: Re: WO Maven getting started
  • Next by Date: Need conceptual modelling advice
  • Previous by thread: Re: Joda LocalTime attribute in ERRest
  • Next by thread: Eclipse WOLips System Frameworks setting not picked up
  • Index(es):
    • Date
    • Thread