Search in sources :

Example 1 with IterableCodec

use of org.bson.codecs.IterableCodec in project LanternPowerMonitor by MarkBryanMilligan.

the class DaoSerializer method parseList.

public static List<DaoEntity> parseList(String _json) {
    try {
        List<DaoEntity> entities = new ArrayList<>();
        JsonReader bsonReader = new JsonReader(_json);
        for (Object o : new IterableCodec(CodecRegistries.fromProviders(Arrays.asList(new ValueCodecProvider(), new BsonValueCodecProvider(), new DocumentCodecProvider())), new BsonTypeClassMap()).decode(bsonReader, DecoderContext.builder().build())) {
            if (o instanceof Document)
                entities.add(new DaoEntity((Document) o));
        }
        return entities;
    } catch (Exception _e) {
        LOG.error("Failed to parse json", _e);
        return null;
    }
}
Also used : ValueCodecProvider(org.bson.codecs.ValueCodecProvider) BsonValueCodecProvider(org.bson.codecs.BsonValueCodecProvider) DocumentCodecProvider(org.bson.codecs.DocumentCodecProvider) ArrayList(java.util.ArrayList) JsonReader(org.bson.json.JsonReader) BsonTypeClassMap(org.bson.codecs.BsonTypeClassMap) Document(org.bson.Document) IterableCodec(org.bson.codecs.IterableCodec) BsonValueCodecProvider(org.bson.codecs.BsonValueCodecProvider)

Aggregations

ArrayList (java.util.ArrayList)1 Document (org.bson.Document)1 BsonTypeClassMap (org.bson.codecs.BsonTypeClassMap)1 BsonValueCodecProvider (org.bson.codecs.BsonValueCodecProvider)1 DocumentCodecProvider (org.bson.codecs.DocumentCodecProvider)1 IterableCodec (org.bson.codecs.IterableCodec)1 ValueCodecProvider (org.bson.codecs.ValueCodecProvider)1 JsonReader (org.bson.json.JsonReader)1