If I dig into the source of ObjectId.java from org.bson.types.ObjectId, I
see that there is an anticipation for the valid id to be a 24 character
hexadecimal represented string.
It looks like ObjectIdField has an implicit dependency on this convention
as well. For example,
*this is from package net.liftweb.mongodb.record.field.ObjectIdField:*
def setFromString(in: String): Box[ObjectId] =
if (ObjectId.isValid(in))
setBox(Full(new ObjectId(in)))
else
setBox(Failure("Invalid ObjectId string: "+in))
Which would mean that anything other than a 24 character long hex
represented string would not get Box'ed with a value.
Am I looking in the wrong place? I'm totally confused.
*This is from org.bson.types.ObjectId:*
public static boolean isValid( String s ){
if ( s == null )
return false;
final int len = s.length();
if ( len != 24 )
return false;
for ( int i=0; i<len; i++ ){
char c = s.charAt( i );
if ( c >= '0' && c <= '9' )
continue;
if ( c >= 'a' && c <= 'f' )
continue;
if ( c >= 'A' && c <= 'F' )
continue;
return false;
}
return true;
}