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

Shai Erera commented on SOLR-6315:
----------------------------------

{quote}
One option for the stated purpose of this issue is to add a boolean flag within 
NamedList (possibly with a getter/setter) to use in JSONResponseWriter. Another 
is to bite the bullet and actually implement an extension of NamedList that 
behaves differently – in this case (based on what I see in JSONResponseWriter 
and the javadocs), preventing duplicates and being more efficient for key 
lookups.
{quote}

This is exactly what I proposed in my last comment -- to make SimpleOrderedMap 
a useful on its own NamedList, by e.g. forbidding duplicates and null values. I 
just have no idea which tests will fail, and e.g. if there are places in the 
code that use SimpleOrderedMap for outputting in "map" form, but rely on being 
able to add multiple values to the same key.

It looks weird to me that we allow that and still output as map, because the 
JSON parser has to do something about these mult-valued keys. So I wrote this 
simple test, to check what happens if you do that:

{code}
public static void main(String[] args) throws Exception {
  JSONResponseWriter writer = new JSONResponseWriter();
  StringWriter sw = new StringWriter();
  SolrQueryRequest req = new LocalSolrQueryRequest(null, new NamedList<Object> 
());
  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("foo", 1);
  rsp.add("foo", 2);
  writer.write(sw, req, rsp);
  String json = sw.toString();
  System.out.println(json);
  
  Map rspMap = (Map)ObjectBuilder.fromJSON(json);
  System.out.println(rspMap);
}
{code}

And it prints:

{noformat}
{"foo":1,"foo":2}

{foo=2}
{noformat}

This makes me believe that whoever uses SimpleOrderedMap does not in fact add 
multiple values to the same key, because at parse time only the last one 
prevails? But I guess Yonik would know the answer to that better.

If indeed that's the case, I think it's best if we just make SimpleOrderedMap 
simple, disallow null and multi-valued keys. And then outputting it in "map" 
style would make sense.

> Remove SimpleOrderedMap
> -----------------------
>
>                 Key: SOLR-6315
>                 URL: https://issues.apache.org/jira/browse/SOLR-6315
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Shai Erera
>            Assignee: Shai Erera
>         Attachments: SOLR-6315.patch
>
>
> As I described on SOLR-912, SimpleOrderedMap is redundant and generally 
> useless class, with confusing jdocs. We should remove it. I'll attach a patch 
> shortly.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to