FAQ
I'm trying to implement Writable interface. but not sure how to
serialize/write/read data from nested objects in

public class StorageClass implements Writable{

public String xStr;
public String yStr;

public List<SubStorage> sStor

//omitted ctors


@override
public void write(DataOutput out) throws IOException{
out.writeChars(xStr);
out.WriteChars(yStr);

//WHAT SHOULD I DO FOR List<SubStorage>

}

@override
public void readFields(DataInput in) throws IOException{
xStr = in.readLine();
yStr = in.readLine();

//WHAT SHOULD I DO FOR List<SubStorage>
}

}

public class SubStorage{
public String x;
public String y;
}

Search Discussions

  • Z3r0c001 at Oct 15, 2009 at 4:01 am
    I'm trying to implement Writable interface. but not sure how to
    serialize/write/read data from nested objects in

    public class StorageClass implements Writable{

    public String xStr;
    public String yStr;

    public List<SubStorage> sStor

    //omitted ctors


    @override
    public void write(DataOutput out) throws IOException{
    out.writeChars(xStr);
    out.WriteChars(yStr);

    //WHAT SHOULD I DO FOR List<SubStorage>

    }

    @override
    public void readFields(DataInput in) throws IOException{
    xStr = in.readLine();
    yStr = in.readLine();

    //WHAT SHOULD I DO FOR List<SubStorage>
    }

    }

    public class SubStorage{
    public String x;
    public String y;
    }
  • Jeff Zhang at Oct 15, 2009 at 6:07 am
    Write:
    first write the length of your list, and then write the item in list one by
    one

    Read:
    read the length of your list, initialized your list and read the item one by
    one, and append the item to list

    I suggest you use array instead of list


    On Thu, Oct 15, 2009 at 12:01 PM, z3r0c001 wrote:

    I'm trying to implement Writable interface. but not sure how to
    serialize/write/read data from nested objects in

    public class StorageClass implements Writable{

    public String xStr;
    public String yStr;

    public List<SubStorage> sStor

    //omitted ctors


    @override
    public void write(DataOutput out) throws IOException{
    out.writeChars(xStr);
    out.WriteChars(yStr);

    //WHAT SHOULD I DO FOR List<SubStorage>

    }

    @override
    public void readFields(DataInput in) throws IOException{
    xStr = in.readLine();
    yStr = in.readLine();

    //WHAT SHOULD I DO FOR List<SubStorage>
    }

    }

    public class SubStorage{
    public String x;
    public String y;
    }
  • Amogh Vasekar at Oct 15, 2009 at 6:16 am
    Hi,
    AFAIK readline is not recommended on DataInput types. Also, look into writableutils to see if something there may be used.
    Hope this helps.

    Amogh


    On 10/15/09 9:31 AM, "z3r0c001" wrote:

    I'm trying to implement Writable interface. but not sure how to
    serialize/write/read data from nested objects in

    public class StorageClass implements Writable{

    public String xStr;
    public String yStr;

    public List<SubStorage> sStor

    //omitted ctors


    @override
    public void write(DataOutput out) throws IOException{
    out.writeChars(xStr);
    out.WriteChars(yStr);

    //WHAT SHOULD I DO FOR List<SubStorage>

    }

    @override
    public void readFields(DataInput in) throws IOException{
    xStr = in.readLine();
    yStr = in.readLine();

    //WHAT SHOULD I DO FOR List<SubStorage>
    }

    }

    public class SubStorage{
    public String x;
    public String y;
    }
  • Eason.Lee at Oct 15, 2009 at 7:53 am
    I think SubStorage should implements Writable as well~~

    Or

    You can try ObjectWritable

    2009/10/15 z3r0c001 <ceo.coder@gmail.com>
    I'm trying to implement Writable interface. but not sure how to
    serialize/write/read data from nested objects in

    public class StorageClass implements Writable{

    public String xStr;
    public String yStr;

    public List<SubStorage> sStor

    //omitted ctors


    @override
    public void write(DataOutput out) throws IOException{
    out.writeChars(xStr);
    out.WriteChars(yStr);

    //WHAT SHOULD I DO FOR List<SubStorage>

    }

    @override
    public void readFields(DataInput in) throws IOException{
    xStr = in.readLine();
    yStr = in.readLine();

    //WHAT SHOULD I DO FOR List<SubStorage>
    }

    }

    public class SubStorage{
    public String x;
    public String y;
    }
  • Jeff Zhang at Oct 15, 2009 at 8:32 am
    agree, you'd better make all the fields implement Writable.

    and then call their read write in your read write function.


    On Thu, Oct 15, 2009 at 3:53 PM, Eason.Lee wrote:

    I think SubStorage should implements Writable as well~~

    Or

    You can try ObjectWritable

    2009/10/15 z3r0c001 <ceo.coder@gmail.com>
    I'm trying to implement Writable interface. but not sure how to
    serialize/write/read data from nested objects in

    public class StorageClass implements Writable{

    public String xStr;
    public String yStr;

    public List<SubStorage> sStor

    //omitted ctors


    @override
    public void write(DataOutput out) throws IOException{
    out.writeChars(xStr);
    out.WriteChars(yStr);

    //WHAT SHOULD I DO FOR List<SubStorage>

    }

    @override
    public void readFields(DataInput in) throws IOException{
    xStr = in.readLine();
    yStr = in.readLine();

    //WHAT SHOULD I DO FOR List<SubStorage>
    }

    }

    public class SubStorage{
    public String x;
    public String y;
    }

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommon-user @
categorieshadoop
postedOct 15, '09 at 4:01a
activeOct 15, '09 at 8:32a
posts6
users4
websitehadoop.apache.org...
irc#hadoop

People

Translate

site design / logo © 2022 Grokbase