Skip to content

Commit

Permalink
Merge pull request #649 from virginOne/master
Browse files Browse the repository at this point in the history
Fix the issue of not being able to import the JSON format
  • Loading branch information
Orbiter authored Jul 10, 2024
2 parents 2f5f3f8 + f3cc818 commit accf4e4
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -152,10 +153,11 @@ private static void setValue(final JSONObject json, final String typeName, final
json.put(name, Double.parseDouble(value));
}
}

public static final void writeDoc(final Writer writer, final SolrDocument doc) throws IOException {
JSONObject json = new JSONObject();
final Map<String, Object> fields = doc.getFieldValueMap();
SimpleDateFormat sdf=new SimpleDateFormat("YYYY-MM-DD'T'hh:mm:ssZ");
for (String key: fields.keySet()) {
if (key == null) continue;
Object value = doc.get(key);
Expand All @@ -165,15 +167,16 @@ public static final void writeDoc(final Writer writer, final SolrDocument doc) t
JSONArray a = new JSONArray();
json.put(key, a);
for (Object o: ((Collection<?>) value)) {
a.put(o);
a.put(o instanceof Date?sdf.format((Date)o):o);
}
} else {
json.put(key, value);
json.put(key, value instanceof Date?sdf.format((Date)value):value);
}
} catch (JSONException e) {
} catch (JSONException | IllegalArgumentException | NullPointerException e) {
throw new IOException(e.getMessage());
}
}

writer.write(json.toString());
writer.write(lb);
}
Expand Down

0 comments on commit accf4e4

Please sign in to comment.