Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"java.sql.Timestamp" dose not be added in or not implement readObject() #24

Open
Tsuki opened this issue Feb 2, 2017 · 9 comments
Open

"java.sql.Timestamp" dose not be added in or not implement readObject() #24

Tsuki opened this issue Feb 2, 2017 · 9 comments

Comments

@Tsuki
Copy link

@Tsuki Tsuki commented Feb 2, 2017

Uncaught Error: Class "java.sql.Timestamp" dose not be added in or not implement readObject()

@Tsuki Tsuki closed this Feb 2, 2017
@Tsuki Tsuki reopened this Feb 3, 2017
@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Feb 3, 2017

Custom class should add by yourself. see https://github.com/node-modules/java.io#4-addobject

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Feb 3, 2017

see unittest for a demo

var io = require('../lib');

@Tsuki
Copy link
Author

@Tsuki Tsuki commented Feb 3, 2017

I decode the timestamp class, the binary is not end with 0x78

        // if(!(tag == cons.TC_OBJECT)){
        //   assert.equal(tag, cons.TC_ENDBLOCKDATA,
        //     'SC_WRITE_METHOD object should end with TC_ENDBLOCKDATA');
        // }

this assert alway wrong, therefore i fork it and comment it.

image

raw.zip

@Tsuki
Copy link
Author

@Tsuki Tsuki commented Feb 3, 2017

Not sure adding Custom class can handle it

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Feb 3, 2017

@Tsuki I try to handle readObject and use your raw.bin

  const io = require('java.io');

  io.addObject('java.sql.Timestamp', {
        readObject(io, obj) {
          console.log('>> java.sql.Timestamp readObject');
          io.readBlockHeader();

          var fastTime = io.readLong().toNumber();
          console.log('<< readObject | fastTime = %s', fastTime);

          obj._$ = new Date(fastTime);
          return obj;
        },

        writeObject(io, obj) {
          io.writeBlockHeader(8);
          io.writeLong(obj._$.getTime());
        },
      });

      var ret = io.ObjectInputStream.read(fs.readFileSync('raw.bin'), true);
      console.log(ret);
{
        '$': {},
        '$class':
         { name: 'java.sql.Timestamp',
           serialVersionUID: '2745179027874758501',
           flags: 2,
           fields: [ { type: 'I', name: 'nanos' } ],
           superClass:
            { name: 'java.util.Date',
              serialVersionUID: '7523967970034938905',
              flags: 3,
              fields: [],
              superClass: null } },
        '_$': new Date('2017-02-03T09:33:02.000Z'),
      }
@Tsuki
Copy link
Author

@Tsuki Tsuki commented Feb 6, 2017

It shoud be have nanos,

when you add io.defaultReadObject(obj);

you will get AssertionError: SC_WRITE_METHOD object should end with TC_ENDBLOCKDATA

{ '$': { nanos: 2015070607 },
  '$class': 
   { name: 'java.sql.Timestamp',
     serialVersionUID: '2745179027874758501',
     flags: 2,
     fields: [ [Object] ],
     superClass: 
      { name: 'java.util.Date',
        serialVersionUID: '7523967970034938905',
        flags: 3,
        fields: [],
        superClass: null } },
  '_$': 2017-02-03T09:44:05.000Z }

@Tsuki
Copy link
Author

@Tsuki Tsuki commented Feb 6, 2017

raw.zip

io.addObject('java.sql.Timestamp', {
  readObject(io, obj) {
    console.log('>> java.sql.Timestamp readObject');
    io.readBlockHeader();

    var fastTime = io.readLong().toNumber();
    console.log('<< readObject | fastTime = %s', fastTime);
    io.defaultReadObject(obj);
    obj._$ = new Date(fastTime);
    io.in.putInt8(120);
    io.in._offset--;
    return obj;
  },

  writeObject(io, obj) {
    io.writeBlockHeader(8);
    io.writeLong(obj._$.getTime());
  },
});

this is my workaround

{ '$': 
   { time: 
      { '$': [Object],
        '$class': [Object],
        '_$': 2017-02-06T01:45:15.000Z },
     time2: 
      { '$': [Object],
        '$class': [Object],
        '_$': 2017-02-06T01:45:15.000Z },
     time3: 
      { '$': [Object],
        '$class': [Object],
        '_$': 2017-02-06T01:45:15.000Z } },
  '$class': 
   { name: 'JavaObjectSerialiser$Test',
     serialVersionUID: '-7238052131403966026',
     flags: 2,
     fields: [ [Object], [Object], [Object] ],
     superClass: null } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.