[JAVA-172] Support alternate naming for boolean getters in ReflectionDBObject Created: 05/Oct/10  Updated: 12/Jul/13  Resolved: 12/Jul/13

Status: Closed
Project: Java Driver
Component/s: Codecs
Affects Version/s: 2.1
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Ilya Brodotsky Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

java version "1.6.0_21"



 Description   

"is"-style getter is ignored by ReflectionObject.

Domain class:
--------------------------------------------------------

package test;

import com.mongodb.ReflectionDBObject;

public class Something extends ReflectionDBObject {
private String kk;
private boolean bb;

public Something(String kk, boolean bb)

{ this.kk = kk; this.bb = bb; }

public String getKk()

{ return kk; }

public void setKk(String kk)

{ this.kk = kk; }

public boolean isBb()

{ return bb; }

public void setBb(boolean bb)

{ this.bb = bb; }

}

Application class:
--------------------------------------------------------

package test;

import com.mongodb.*;

import java.net.UnknownHostException;

public class BooleanGetterApp {
public static void main(String[] args) {
try

{ Mongo m = new Mongo("localhost", 27017); DB db = m.getDB("mydb"); DBCollection coll = db.getCollection("testCollection"); coll.drop(); Something something = new Something("kk", true); coll.save(something); DBObject dbObject = coll.findOne(); System.out.println(dbObject.toString()); }

catch (UnknownHostException e)

{ e.printStackTrace(); }

}
}

Application output:
--------------------------------------------------------

{ "_id" :

{ "$oid" : "4cab3c5417066088cabbebf3"}

, "Kk" : "kk"}

– boolean value was ignored.



 Comments   
Comment by Jeffrey Yemin [ 12/Jul/13 ]

In 3.0 we're going to have much better support for encoding and decoding, but not through ReflectionDBObject. So we're going to just leave this alone.

Comment by Jeffrey Yemin [ 28/Apr/12 ]

We should probably use java.beans.Introspector#getBeanInfo instead of rolling our own introspector in com.mongodb.ReflectionDBObject.JavaWrapper

Generated at Thu Feb 08 08:51:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.