Thanks for your help (i mean all :) )
At last i used a conversion class helper like i did before in struts, passing in the value, default value and returning the object expected.
Thanks again,
Jordi
Date: Wed, 23 Sep 2009 20:39:12 +0200
From: Paul.Sandoz_at_Sun.COM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] 400 Bad Request (bug?)
On Sep 23, 2009, at 8:26 PM, Craig McClanahan wrote: Paul Sandoz wrote:
On Sep 23, 2009, at 3:51 AM, Jordi Domingo wrote: I know what happens with Java :)
What I expected is Jersey check the value before doing the conversion and then setting the value to null. Tomorrow i will think the best approach to solve this.
The value will be null if and only if the parameter is not declared in the request.
If the parameter is declared then the value of that parameter will be converted accordingly and errors may result if the value cannot be converted, and the error is reported back to the client.
What null means is *absence* of the parameter and not absence of a parameter value.
IIUC what you want is the ability to consider the following cases semantically equivalent:
1) absence of a parameter; and
2) absence of a parameter value;
There are a number of approaches you can utilize:
1) Use a type of List<Long>, check if there is one or more entries, and use the first entry if not null. A null entry value in a list declares that the parameter was present but the value was absent.
2) Implement is to support a request filter that obtains the form parameters, removes all parameters that have empty values, then re-serializes the form contents.
3) Implement support for a StringReaderProvider [1] that supports the known concrete types that extend Number, such that an empty String value will return null. This could be generalized to support the type, say, ParamValue<T> where the T is deferred to by StringReaderWorkers. A value of ParamValue<T> that holds null declared the parameter was present but has no value.
If people think that ParamValue<T> then i can implement support for that. It would be nice to have the *option* to configure conversion of empty strings to null values (via ParamValue<T>), but this should not be the default behavior
I agree.
-- it will trigger no end of head scratching "how in the world did I get a null pointer exception *there*" type questions otherwise. And, as Jordi pointed out originally, an empty string is semantically different from a null. (Oh, I guess not if you're using an Oracle database, but that's a different story :-).
:-)
If the client doesn't want to send a value for a field, it should not send that field at all.
Agreed.
Paul.
_________________________________________________________________
¿Quieres ver los mejores videos de MSN? Enciende Messenger TV
http://messengertv.msn.com/mkt/es-es/default.htm
--_9bcb8ce5-da16-4a1e-acda-bf805e574975_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Thanks for your help (i mean all :) )<div><br></div><div>At last i used a conversion class helper like i did before in struts, passing in the value, default value and returning the object expected.</div><div><br></div><div>Thanks again,</div><div><br></div><div>Jordi<br><br><hr id="stopSpelling">Date: Wed, 23 Sep 2009 20:39:12 +0200<br>From: Paul.Sandoz@Sun.COM<br>To: users@jersey.dev.java.net<br>Subject: Re: [Jersey] 400 Bad Request (bug?)<br><br><br><div><div>On Sep 23, 2009, at 8:26 PM, Craig McClanahan wrote:</div><br class="ecxApple-interchange-newline"><blockquote> <div> Paul Sandoz wrote: <blockquote cite="mid:00910A5C-15FF-4B49-B07E-512AC1AEA3C6@Sun.Com"><br> <div> <div>On Sep 23, 2009, at 3:51 AM, Jordi Domingo wrote:</div> <br class="ecxApple-interchange-newline"> <blockquote><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"> <div class="ecxhmmessage" style="font-size:10pt;font-family:Verdana">I know what happens with Java :) <div><br> </div> <div>What I expected is Jersey check the value before doing the conversion and then setting the value to null. Tomorrow i will think the best approach to solve this.</div> <div><br> </div> </div> </span></blockquote> <div><br> </div> The value will be null if and only if the parameter is not declared in the request.</div> <div><br> </div> <div>If the parameter is declared then the value of that parameter will be converted accordingly and errors may result if the value cannot be converted, and the error is reported back to the client.</div> <div><br> </div> <div>What null means is *absence* of the parameter and not absence of a parameter value.</div> <div><br> </div> <div>IIUC what you want is the ability to consider the following cases semantically equivalent:</div> <div><br> </div> <div> 1) absence of a parameter; and</div> <div><br> </div> <div> 2) absence of a parameter value;</div> <div><br> </div> <div><br> </div> <div>There are a number of approaches you can utilize:</div> <div><br> </div> <div>1) Use a type of List<Long>, check if there is one or more entries, and use the first entry if not null.</div> <div> A null entry value in a list declares that the parameter was present but the value was absent.</div> <div><br> </div> <div>2) Implement is to support a request filter that obtains the form parameters, removes all parameters that have </div> <div> empty values, then re-serializes the form contents.</div> <div><br> </div> <div>3) Implement support for a StringReaderProvider [1] that supports the known concrete types that extend Number, </div> <div> such that an empty String value will return null. This could be generalized to support the type, say,</div> <div> ParamValue<T> where the T is deferred to by StringReaderWorkers. A value of ParamValue<T> that holds</div> <div> null declared the parameter was present but has no value.</div> <div><br> </div> <div>If people think that ParamValue<T> then i can implement support for that.</div> </blockquote> It would be nice to have the *option* to configure conversion of empty strings to null values (via ParamValue<T>), but this should not be the default behavior</div></blockquote><div><br></div>I agree.</div><div><br></div><div><br><blockquote><div> -- it will trigger no end of head scratching "how in the world did I get a null pointer exception *there*" type questions otherwise. And, as Jordi pointed out originally, an empty string is semantically different from a null. (Oh, I guess not if you're using an Oracle database, but that's a different story :-).<br> <br></div></blockquote><div><br></div>:-)</div><div><br></div><div><br><blockquote><div> If the client doesn't want to send a value for a field, it should not send that field at all.<br></div></blockquote><div><br></div>Agreed.</div><div><br></div><div>Paul.</div></div> <br /><hr />Comparte tus fotos con tus amigos. Más fácil con <a href='
http://download.live.com' target='_new'>Windows Live</a></body>
</html>
--_9bcb8ce5-da16-4a1e-acda-bf805e574975_--