org.bson.BsonUndefined Java Examples
The following examples show how to use
org.bson.BsonUndefined.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BsonTypeMap.java From morphia with Apache License 2.0 | 6 votes |
/** * Creates the map */ public BsonTypeMap() { map.put(List.class, BsonType.ARRAY); map.put(Binary.class, BsonType.BINARY); map.put(Boolean.class, BsonType.BOOLEAN); map.put(Date.class, BsonType.DATE_TIME); map.put(BsonDbPointer.class, BsonType.DB_POINTER); map.put(Document.class, BsonType.DOCUMENT); map.put(Double.class, BsonType.DOUBLE); map.put(Integer.class, BsonType.INT32); map.put(Long.class, BsonType.INT64); map.put(Decimal128.class, BsonType.DECIMAL128); map.put(MaxKey.class, BsonType.MAX_KEY); map.put(MinKey.class, BsonType.MIN_KEY); map.put(Code.class, BsonType.JAVASCRIPT); map.put(CodeWithScope.class, BsonType.JAVASCRIPT_WITH_SCOPE); map.put(ObjectId.class, BsonType.OBJECT_ID); map.put(BsonRegularExpression.class, BsonType.REGULAR_EXPRESSION); map.put(String.class, BsonType.STRING); map.put(Symbol.class, BsonType.SYMBOL); map.put(BsonTimestamp.class, BsonType.TIMESTAMP); map.put(BsonUndefined.class, BsonType.UNDEFINED); }
Example #2
Source File: TypeConversionTest.java From immutables with Apache License 2.0 | 5 votes |
@Test void undefined() throws IOException { JsonParser parser = Parsers.parserAt(new BsonUndefined()); check(parser.currentToken()).is(JsonToken.VALUE_NULL); check(parser.getText()).is(JsonToken.VALUE_NULL.asString()); parser.nextToken(); }
Example #3
Source File: WritecontextTest.java From pinpoint with Apache License 2.0 | 4 votes |
@Test public void parseBsonArrayWithValues() throws IOException { BsonValue a = new BsonString("stest"); BsonValue b = new BsonDouble(111); BsonValue c = new BsonBoolean(true); BsonDocument document = new BsonDocument() .append("int32", new BsonInt32(12)) .append("int64", new BsonInt64(77L)) .append("bo\"olean", new BsonBoolean(true)) .append("date", new BsonDateTime(new Date().getTime())) .append("double", new BsonDouble(12.3)) .append("string", new BsonString("pinpoint")) .append("objectId", new BsonObjectId(new ObjectId())) .append("code", new BsonJavaScript("int i = 10;")) .append("codeWithScope", new BsonJavaScriptWithScope("int x = y", new BsonDocument("y", new BsonInt32(1)))) .append("regex", new BsonRegularExpression("^test.*regex.*xyz$", "big")) .append("symbol", new BsonSymbol("wow")) .append("timestamp", new BsonTimestamp(0x12345678, 5)) .append("undefined", new BsonUndefined()) .append("binary1", new BsonBinary(new byte[]{(byte) 0xe0, 0x4f, (byte) 0xd0, 0x20})) .append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[]{1, 1, 1, 1, 1})) .append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7)))) .append("document", new BsonDocument("a", new BsonInt32(77))) .append("dbPointer", new BsonDbPointer("db.coll", new ObjectId())) .append("null", new BsonNull()) .append("decimal128", new BsonDecimal128(new Decimal128(55))); BasicDBObject query = new BasicDBObject(); query.put("ComplexBson", document); logger.debug("document:{}", document); NormalizedBson stringStringValue = MongoUtil.parseBson(new Object[]{query}, true); logger.debug("val:{}", stringStringValue); List list = objectMapper.readValue("[" + stringStringValue.getNormalizedBson() + "]", List.class); Assert.assertEquals(list.size(), 1); Map<String, ?> query1Map = (Map<String, ?>) list.get(0); checkValue(query1Map); }
Example #4
Source File: MongoField.java From pentaho-mongodb-plugin with Apache License 2.0 | 4 votes |
/** * Convert a mongo record object to a Kettle field value (for the field defined by this path) * * @param mongoObject * the record to convert * @return the kettle field value * @throws KettleException * if a problem occurs */ public Object convertToKettleValue( BasicDBObject mongoObject ) throws KettleException { if ( mongoObject == null ) { return null; } if ( m_tempParts.size() == 0 ) { throw new KettleException( BaseMessages.getString( PKG, "MongoDbInput.ErrorMessage.MalformedPathRecord" ) ); //$NON-NLS-1$ } String part = m_tempParts.remove( 0 ); if ( part.charAt( 0 ) == '[' ) { // we're not expecting an array at this point - this document does not // contain our field return null; } if ( part.indexOf( '[' ) > 0 ) { String arrayPart = part.substring( part.indexOf( '[' ) ); part = part.substring( 0, part.indexOf( '[' ) ); // put the array section back into location zero m_tempParts.add( 0, arrayPart ); } // part is a named field of this record Object fieldValue = mongoObject.get( part ); if ( fieldValue == null || fieldValue.getClass().equals( BsonUndefined.class ) ) { return null; } // what have we got if ( m_tempParts.size() == 0 ) { // we're expecting a leaf primitive - lets see if that's what we have // here... return getKettleValue( fieldValue ); } if ( fieldValue instanceof BasicDBObject ) { return convertToKettleValue( ( (BasicDBObject) fieldValue ) ); } if ( fieldValue instanceof BasicDBList ) { return convertToKettleValue( ( (BasicDBList) fieldValue ) ); } // must mean we have a primitive here, but we're expecting to process more // path so this doesn't match us - return null return null; }
Example #5
Source File: TypeConversionTest.java From immutables with Apache License 2.0 | 4 votes |
@Test public void undefined() throws IOException { JsonReader reader = Jsons.readerAt(new BsonUndefined()); check(reader.peek()).is(JsonToken.NULL); reader.nextNull(); }
Example #6
Source File: DocumentWriter.java From morphia with Apache License 2.0 | 4 votes |
@Override public void writeUndefined() { state.value(new BsonUndefined()); }