You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "Mike Drob (Jira)" <ji...@apache.org> on 2022/03/15 18:52:00 UTC

[jira] [Commented] (SOLR-16101) Add an empty constructor for SolrInputDocument

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

Mike Drob commented on SOLR-16101:
----------------------------------

If we're going to add this now, after having declined to do so in the linked issues, we should at least document clearly in the no-arg constructor why it exists so that it would not get removed again in the future by somebody doing "clean up" work.

 

For what it's worth, GSON lets you register an [instance creator|https://github.com/google/gson/blob/master/UserGuide.md#TOC-Writing-an-Instance-Creator] that I think would handle this particular case for you as a workaround (or anybody reading this in the future who needs it to work on an older version that is missing the constructor).

> Add an empty constructor for SolrInputDocument
> ----------------------------------------------
>
>                 Key: SOLR-16101
>                 URL: https://issues.apache.org/jira/browse/SOLR-16101
>             Project: Solr
>          Issue Type: Bug
>      Security Level: Public(Default Security Level. Issues are Public) 
>          Components: SolrJ
>    Affects Versions: 5.5, 6.6, 7.7, 8.11.1
>            Reporter: Anshum Gupta
>            Assignee: Anshum Gupta
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> While trying to serialize and deserialize {{SolrInputDocument}} using the following code, 
> {code:java}
> final SolrInputDocument inputDoc = new SolrInputDocument();
>         inputDoc.addField("foo", "bar");
>         Gson gson = new Gson();
>         String docString = gson.toJson(inputDoc);
>         SolrInputDocument solrInputDocument = new SolrInputDocument(gson.fromJson(docString, SolrInputDocument.class));
> {code}
> the deserializing fails w/ 
> bq. "java.lang.ClassCastException: Cannot cast com.google.gson.internal.LinkedTreeMap to org.apache.solr.common.SolrInputDocument"
> {{SolrInputDocument}} needs an empty constructor for this.
> There seem to be some ways to get around this for older versions but with vanilla code this affects all versions starting 5.5 all the way until 8.11.1



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org