commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Haggood <codezi...@email.com>
Subject Null exception using Beanutils.copyproperties on POJO and JSONDynabean
Date Sun, 19 Nov 2006 16:33:50 GMT
I have a JSONOBject I've turned into a Dynabean, then I'm trying to
populate the related POJO on the server side, but I keep getting a
NullpointerException.

Function, POJO (and it's base hierarchy) and the stacktrace are below:


/*****************************************************
/* JSONObject
*****************************************************/

jsob.ToString() = "{\"today\":{\"month\":10,\"day\":0,\"year\":106,
\"seconds\":59,\"time\":1.163953559956E12,\"date\":19,\"timezoneOffset
\":300,\"hours\":11,\"minutes\":25},\"phonenumber\":\"313.555.1212\",
\"type\":\"net.codezilla.unitycore.sample.AddressBookEntry\",\"address
\":\"123 Main\",\"email\":\"nate@wayne.edu\",\"docname\":\"\",\"docURL
\":\"\",\"name\":\"Johnson, Nate\",\"fullname\":\"Johnson, Nate\",\"id
\":91}"


/*****************************************************
/* Function using BeanUtils.copyProperties
*****************************************************/


// If I have the objectKey, this must be an edit so just retrieve the
existing
    // persistance wrapper (UBO) and update the beans.
    private int putJSONUnityObject(int okey, JSONObject jsob){
        int rval = 0;
        try {

        // get the token for this object
            int tokenkey = getObjectTokenID(okey);
            // retrieve the subclass of UBO for this token
            UnityBaseObject ubo =
getGenericService().getObject(tokenkey);
	    // Turn jsonobject into Dynabean
            Object mybean = JSONObject.toBean(jsob);
            BeanUtils mb = new BeanUtils();
            mb.copyProperties(ubo,mybean);
            //ubo.setId(okey);
            int cFolder = this.getCurrentFolderID();
            rval = this.storeUnityObject(ubo,cFolder);
        } catch (Exception e) {
            e.printStackTrace();
        }


        return rval;
    }


/*****************************************************
/* My POJO
*****************************************************/

public class AddressBookEntry extends UnityDocument {
    
    private String fullname, address, phonenumber, email;

    /** Creates a new instance of AddressBookEntry */
    public AddressBookEntry(String fname, String addr, String phone,
String em) {
        fullname=fname;
        address=addr;
        phonenumber=phone;
        email =em;
    }
    
    public AddressBookEntry(){
    
    }
    
    public String getName(){
        return getFullname();
    }
    
    
    public boolean validate(){
        return isValid;
    }
    
    
    public String getFullname() {
        return fullname;
    }
    
    public void setFullname(String fname) {
        this.fullname = fname;
    }
    
    
    public String getAddress() {
        return address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }
    
    public String getPhonenumber() {
        return phonenumber;
    }
    
    public void setPhonenumber(String phonenumber) {
        this.phonenumber = phonenumber;
    }
    
    public String getEmail() {
        return email;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }    
}

/*****************************************************
/*** POJO Base Objects
*****************************************************/

package net.codezilla.unitycore.base;

import java.util.Vector;

/**
 *
 * @author pbh
 */
public class UnityDocument extends UnityBaseObject {
    private String docName;
    private String docURL;
    
    public UnityDocument(){
    }
    
    /** Creates a new instance of UnityDocument */
    public UnityDocument( String dname) {
        this.setDocname(dname);
    }
    
    
    public String getName(){
        return this.getDocname();
    }
        
    public boolean validate(){
        return isValid;
    }
    
    public String getType(){
        return this.getClass().getName();
    }
    
    public String getDocname() {
        return docName;
    }
    
    public void setDocname(String docname) {
        this.docName = docname;
    }
    
    public String getDocURL() {
        return docURL;
    }
    
    public void setDocURL(String docURL) {
        this.docURL = docURL;
    }
    
    
}

/*****************************************************
//******* Base Doc
*****************************************************/

package net.codezilla.unitycore.base;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 *
 * @author pbh
 */
public abstract class UnityBaseObject {
    int id = -1;
    protected boolean isValid=false;
    
    
    
    /** Creates a new instance of UnityBaseObject */
    public UnityBaseObject() {
    }
    
    
    
    /** Assign the persistant store id from the key generator
     * @param dbcon A database controller object
     */
    public void setId(int oid){
        id = oid;
    }
    
    
    /** Retrieve the persistant store id from the key generator
     * @param dbcon A database controller object
     */
    public int getId() {
        return id;
    }
   
    
    public Date getToday(){
        return new Date();
    }
    
    /** Stub to return whatever function the extending object uses to
identify itself in a list
     */
    public abstract String getName();
    public abstract String getType();
    /** Stub for the object's custom validation process
     */
    public abstract boolean validate();  // is object ready for storage?
}

/*****************************************************
 * Stacktrace
*****************************************************/

java.lang.NullPointerException
        at
org.apache.commons.beanutils.BeanUtilsBean.copyProperties(BeanUtilsBean.java:232)
        at
org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:114)
        at
net.codezilla.unitycore.renderbot.gwt.UnityJSONServiceManager.putJSONUnityObject(UnityJSONServiceManager.java:308)
        at
net.codezilla.unitycore.renderbot.gwt.UnityJSONServiceManager.putJSONUnityObject(UnityJSONServiceManager.java:376)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
com.metaparadigm.jsonrpc.JSONRPCBridge.call(JSONRPCBridge.java:1122)
        at
com.metaparadigm.jsonrpc.JSONRPCServlet.service(JSONRPCServlet.java:163)
        at
GWTApplication.server.UnityServlet.service(UnityServlet.java:45)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at
com.google.gwt.dev.shell.GWTShellServlet.service(GWTShellServlet.java:216)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
        at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
        at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
        at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
        at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadPool.java:683)
        at java.lang.Thread.run(Thread.java:595)


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message