Re: [Resteasy-users] @Form and non-alpha map keys

2012-11-30 Thread John Reiter
Weinan, I just entered a JIRA ticket for this issue:

https://issues.jboss.org/browse/RESTEASY-805

Thanks!

John

On Fri, Nov 30, 2012 at 2:57 AM, Weinan Li l.wei...@gmail.com wrote:



 --
 Weinan Li


 On Thursday, November 29, 2012 at 11:58 PM, John Reiter wrote:

 I know it's obvious from the regex, but it looks like map keys with
 numbers also wouldn't work right now (all I've tested is the case I
 outlined in my email though).

 Hi John ,could you please sum up your problem and create a JIRA? I'll work
 on it, thanks!

 John

 On Thu, Nov 29, 2012 at 10:41 AM, Bill Burke bbu...@redhat.com wrote:

 I don't see a reason why this couldn't be fixed.


 On 11/29/2012 8:33 AM, Weinan Li wrote:

 Hi Bill,

 Do you think we could support '-' for map key?

 --
 Weinan Li


 On Tuesday, November 27, 2012 at 12:45 AM, John Reiter wrote:

  Hello,

 I'm having an issue with RESTEasy 2.3.4 with using @Form/@FormParam
 annotations to set values of a Map that uses UUIDs for its keys.  My
 classes basically look like this:

 @Controller
 @Path( /test )
 public class MyController
 {
 @Consumes( MediaType.APPLICATION_FORM_**URLENCODED )
 @POST
 public ModelAndView setAssignments( @Form final MyForm myForm )
 throws URISyntaxException
 { ... }
 }

 public class MyForm
 {
 @Form( prefix = myMap )
 private MapString, Foo myMap = Maps.newHashMap();
 }

 public class Foo
 {
 @FormParam( bar )
 public void setBar( final String bar )
{ ... }
 }

 The request parameters that get submitted look like this:

 myMap[75736572-3100-505f-dac0-**000745b8].bar
 myMap[b794c4a0-14b7-0130-c2da-**20c9d04983db].bar
 etc.

 The Foo.bar properties never end up being set.  Stepping through with
 a debugger, the problem occurs in
 AbstractCollectionFormInjector**.**findMatchingPrefixesWithNoneEm**
 ptyValues():
 that method tries to find keys in the map that match a regex.  In this
 case, the regex is defined in MapFormInjector:

public MapFormInjector(Class collectionType, Class keyType, Class
 valueType, String prefix, ResteasyProviderFactory factory)
{
   super(collectionType, valueType, prefix, Pattern.compile(^ +
 prefix + \\[([a-zA-Z_]+)\\]), factory);
   keyInjector = new StringParameterInjector(**keyType, keyType,
 null, Form.class, null, null, new Annotation[0], factory);
}

 And only allows alpha characters and underscores, which is obviously
 why my map isn't being populated.  I'm working around this right now
 by mapping temporary, alpha-only keys to the real ones and using those
 in my form then replacing them after the form is submitted.  Is there
 a way to get this regex changed to be something a little more
 lenient?  Really, is there any reason to disallow anything other than
 maybe brackets?

 If you want me to enter a JIRA issue for this, let me know.

 Thanks,
 John




 --**--**
 --
 Monitor your physical, virtual and cloud infrastructure from a single
 web console. Get in-depth insight into apps, servers, databases, vmware,
 SAP, cloud infrastructure, etc. Download 30-day Free Trial.
 Pricing starts from $795 for 25 servers or applications!
 http://p.sf.net/sfu/zoho_**dev2dev_novhttp://p.sf.net/sfu/zoho_dev2dev_nov
 __**_
 Resteasy-users mailing list
 Resteasy-users@lists.**sourceforge.netResteasy-users@lists.sourceforge.net
 mailto:Resteasy-users@lists.**sourceforge.netResteasy-users@lists.sourceforge.net
 
 https://lists.sourceforge.net/**lists/listinfo/resteasy-usershttps://lists.sourceforge.net/lists/listinfo/resteasy-users



 --
 Bill Burke
 JBoss, a division of Red Hat
 http://bill.burkecentral.com




--
Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.
http://goparallel.sourceforge.net___
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users


[Resteasy-users] @Form and non-alpha map keys

2012-11-26 Thread John Reiter
Hello,

I'm having an issue with RESTEasy 2.3.4 with using @Form/@FormParam
annotations to set values of a Map that uses UUIDs for its keys.  My
classes basically look like this:

@Controller
@Path( /test )
public class MyController
{
@Consumes( MediaType.APPLICATION_FORM_URLENCODED )
@POST
public ModelAndView setAssignments( @Form final MyForm myForm )
throws URISyntaxException
{ ... }
}

public class MyForm
{
@Form( prefix = myMap )
private MapString, Foo myMap = Maps.newHashMap();
}

public class Foo
{
@FormParam( bar )
public void setBar( final String bar )
   { ... }
}

The request parameters that get submitted look like this:

myMap[75736572-3100-505f-dac0-000745b8].bar
myMap[b794c4a0-14b7-0130-c2da-20c9d04983db].bar
etc.

The Foo.bar properties never end up being set.  Stepping through with a
debugger, the problem occurs in
AbstractCollectionFormInjector.findMatchingPrefixesWithNoneEmptyValues():
that method tries to find keys in the map that match a regex.  In this
case, the regex is defined in MapFormInjector:

   public MapFormInjector(Class collectionType, Class keyType, Class
valueType, String prefix, ResteasyProviderFactory factory)
   {
  super(collectionType, valueType, prefix, Pattern.compile(^ + prefix
+ \\[([a-zA-Z_]+)\\]), factory);
  keyInjector = new StringParameterInjector(keyType, keyType, null,
Form.class, null, null, new Annotation[0], factory);
   }

And only allows alpha characters and underscores, which is obviously why my
map isn't being populated.  I'm working around this right now by mapping
temporary, alpha-only keys to the real ones and using those in my form then
replacing them after the form is submitted.  Is there a way to get this
regex changed to be something a little more lenient?  Really, is there any
reason to disallow anything other than maybe brackets?

If you want me to enter a JIRA issue for this, let me know.

Thanks,
John
--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov___
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users


[Resteasy-users] Customizing Jackson mapper

2012-08-31 Thread John Reiter
I'm using JBoss AS 7.1.1.Final, the included RESTEasy distribution
(2.3.2.Final), and Jackson 1.9.9 to handle serialization/deserialization
to/from JSON.  I can serialize/deserialize JSON using @Produces/@Consumes
along with Jackson annotations in my REST resources and this all works
fine.  The problem I'm having is I'd like to start customizing some Jackson
behavior and register custom serializers/deserializers and can't quite get
this working.  This should involve getting access to the RESTEasy Jackson
ObjectMapper and running my customization code on that mapper.

After seeing something similar in a forum post, I tried this:

@Provider
@Consumes({ MediaType.APPLICATION_JSON, text/json })
@Produces({ MediaType.APPLICATION_JSON, text/json })
public class JacksonCustomizations extends ResteasyJacksonProvider {

private static final Logger log = Logger.getLogger(
JacksonCustomizations.class );

public JacksonCustomizations()
{
super();

log.info( Beginning Jackson configuration... );

final ObjectMapper mapper = _mapperConfig.getConfiguredMapper();

final Version version = new Version( 0, 0, 1, null );
final SimpleModule module = new SimpleModule( Test Module,
version );

//Add custom serializers
module.addSerializer( LocalDate.class, new
JacksonLocalDate.Serializer() );

//Add custom deserializers
module.addDeserializer( LocalDate.class, new
JacksonLocalDate.Deserializer() );

mapper.registerModule( module );

log.info( OK: Finished configuring Jackson );
}
}

But this code doesn't seem to ever run.  I receive JSON back from my
application as normal, but I don't see any log entries and my custom
serializers/deserializers don't seem to be registered (@JsonSerialize(
using = JacksonLocalDate.Serializer.class seems to have no effect).

Is this a valid approach to solving this problem or should I be going about
it in an entirely different way?  If this is valid, does anyone have any
suggestions about what might be wrong with my implementation?  If not, has
anyone had success with a different approach?

Thanks,
John
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users