You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Noble Paul (JIRA)" <ji...@apache.org> on 2017/05/17 03:21:04 UTC

[jira] [Commented] (SOLR-10413) v2 API: parsed JSON type should be coerced to expected type

    [ https://issues.apache.org/jira/browse/SOLR-10413?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16013462#comment-16013462 ] 

Noble Paul commented on SOLR-10413:
-----------------------------------

let us not reflection here
{code}
  String className = Character.toUpperCase(fname.toString().charAt(0))
          + fname.toString().substring(1) + "Validator";
      Class<Validator> validatorClass = getValidatorClass(fname, className);
      Constructor<Validator> constructor = (Constructor<Validator>) validatorClass.getDeclaredConstructors()[0];
{code}
We have a well defined set of Validators . You can keep a Map of fname vs. Validator objects and lookup

> v2 API: parsed JSON type should be coerced to expected type
> -----------------------------------------------------------
>
>                 Key: SOLR-10413
>                 URL: https://issues.apache.org/jira/browse/SOLR-10413
>             Project: Solr
>          Issue Type: Bug
>      Security Level: Public(Default Security Level. Issues are Public) 
>          Components: v2 API
>            Reporter: Steve Rowe
>            Priority: Minor
>         Attachments: SOLR-10413.patch
>
>
> v2 API request bodies are parsed as JSON and are checked via JSON schema for the correct types.  But since the JSON parser used (noggit) accepts a relaxed form of JSON, it is weirdly necessary to quote some things but not others.
> For example, after {{bin/solr start -e cloud -noprompt}}, {{curl http://localhost:8983/v2/cluster -H 'Content-type: application/json' -d '\{ set-property: \{ name: autoAddReplicas, val: false \} \}'}} returns:
> {noformat}
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
> <title>Error 400 {metadata={error-class=org.apache.solr.api.ApiBag$ExceptionWithErrObject,root-error-class=org.apache.solr.api.ApiBag$ExceptionWithErrObject},errorMessages=[{set-property={name=autoAddReplicas, val=false}, errorMessages=[Expected type : string but found : falsein object : false]}],msg=Error in command payload,code=400}</title>
> </head>
> <body><h2>HTTP ERROR 400</h2>
> <p>Problem accessing /solr/____v2/cluster. Reason:
> <pre>    {metadata={error-class=org.apache.solr.api.ApiBag$ExceptionWithErrObject,root-error-class=org.apache.solr.api.ApiBag$ExceptionWithErrObject},errorMessages=[{set-property={name=autoAddReplicas, val=false}, errorMessages=[Expected type : string but found : falsein object : false]}],msg=Error in command payload,code=400}</pre></p>
> </body>
> </html>
> {noformat}
> By contrast, if I quote the propery value, the request succeeds: {{curl http://localhost:8983/v2/cluster -H 'Content-type: application/json' -d '\{ set-property: \{ name: autoAddReplicas, val: "false" \} \}'}}
> This is annoying because the property is semantically boolean, even though cluster properties' keys and values are always typed String.
> This error occurs because the API spec for the v2 Cluster API's {{set-property}} command requires {{string}} typed values - from {{solr/core/src/resources/apispec/cluster.Commands.json}}: 
> {noformat}
> {
>   "documentation": [...],
>   "description": [...],
>   "methods": [ "POST" ],
>   "url": { "paths": [ "/cluster" ] },
>   "commands": {
> [...]
>     "set-property": {
>       "type": "object",
>       "documentation": [...],
>       "description": [...],
>       "properties": {
>         "name": { "type": "string",  "description": [...] },
>         "val": { "type": "string", "description": [...] }
> [...]
> {noformat}
> I'm not sure how wide-spread the problem is, but at a minimum for this particular API (setting a cluster property), Solr should accept both keys and values of any (JSON) type and just {{toString()}} their values.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org