Package Exports
- hessian.js
- hessian.js/lib/utils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hessian.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
hessian.js

Hessian Serialization 1.0 written by pure JavaScript. Support all kind of types in Java.
Install
npm install hessian.jsSupport Types
8 primitive types:
- raw binary data
- boolean
- 64-bit millisecond date
- 64-bit double
- 32-bit int
- 64-bit long
- null
- UTF8-encoded string
3 recursive types:
- list for lists and arrays
- map for maps and dictionaries
- object for objects
one special contruct:
- ref for shared and circular object references
Encoder
Simple javascript type
var hessian = require('hessian.js');
var encoder = new hessian.Encoder();
encoder.write(1); // int
encoder.write(1.1); // double
encoder.write(1e100); // double
encoder.write(Math.pow(2, 18)); // long
encoder.write(true); // boolean
encoder.write(null); // null
encoder.write('test'); // string
// java base types
encoder.write(hessian.java.long(3001010320)); // 3001010320L
encoder.write(hessian.java.double(100)); // double
encoder.write(hessian.java.intList([0, 1, 2])); // int[] = {0, 1, 2}
var object = {};
object.prop1 = [1, 2, 3];
object.prop2 = 'string';
object.prop3 = {key: 'value'};
object.prop4 = object; // circular
encoder.write(object); // objectComplex java type
var hessian = require('hessian.js');
var encoder = new hessian.Encoder();
var long = {
$class: 'java.lang.Long',
$: 1
}
encoder.write(long); // long type
var testObject = {
$class: 'com.hessian.TestObject',
$: {
a: 1,
b: 'test',
c: {$class: 'java.lang.Long', $: 123}
}
};
encoder.write(testObject);Decoder
var hessian = require('hessian.js');
var decoder = new hessian.Decoder(buf);
decoder.read(); //return what it is
decoder.readNull();
decoder.readBool();
decoder.readInt();
decoder.readLong();
decoder.readDouble();
decoder.readDate();
decoder.readObect();
decoder.readMap();
decoder.readArray();
decoder.readList();
decoder.readRef();Simple Usage
var hessian = require('hessian.js');
var testObject = {
a: 1,
b: 'string',
c: true,
d: 1.1,
e: Math.pow(2, 40),
f: [1, 2, 3, '4', true, 5],
g: {a: 1, b: true, c: 'string'}
};
var buf;
try {
buf = hessian.encode(testObject);
} catch (err) {
console.log('encode error: ', err.message);
process.exit(1);
}
try {
var res = hessian.decode(buf);
// res.should.eql(testObject);
} catch (err) {
console.log('decode error: ', err.message);
}TODO
- more unit test, include test with other language.
- benchmark test.
- maybe support hessian 2.x.
Hessian Serialization 2.0 has 3 internal reference maps:
- An object/list reference map.
- An class definition reference map.
- A type (class name) reference map.
Authors
$ git summary
project : hessian.js
repo age : 2 weeks ago
commits : 35
active : 9 days
files : 29
authors :
27 dead_horse 77.1%
8 fengmk2 22.9%Licences
(The MIT License)
Copyright (c) 2014 dead-horse and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.