/**
 * Copyright (c) 2010-2015, openHAB.org and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.zwave.internal;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

/**
 * Implements a Hex value to integer converter and vice versa.
 * 
 * @author Jan-Willem Spuij
 * @since 1.4.0
 */
public class HexToIntegerConverter implements Converter {

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public boolean canConvert(Class type) {
		return type.equals(Integer.class) || type.equals(int.class);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
		int number = (Integer) source;
		writer.setValue("0x" + Integer.toHexString(number));
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		String value = reader.getValue();
		if(value.startsWith("0x"))
			return Integer.decode(value);
		else
			return Integer.parseInt(value, 16);
	}

}
@@ -1204,23 +1204,20 @@
 (%220x%22 + 
-Integer
+Long
 .toHexSt
@@ -1428,16 +1428,18 @@
 h(%220x%22))
+ %7B
 %0A%09%09%09retu
@@ -1441,23 +1441,20 @@
 %09return 
-Integer
+Long
 .decode(
@@ -1465,14 +1465,20 @@
 e);%0A
+%09%09%7D%0A
 %09%09else
+ %7B
 %0A%09%09%09
@@ -1488,24 +1488,22 @@
 urn 
-Integer
+Long
 .parse
-Int
+Long
 (val
@@ -1511,13 +1511,16 @@
 e, 16);%0A
+%09
 %09%7D%0A
+%09%7D
 %0A%7D

Fix bug deserialising large/negative hex numbers