|
20 | 20 |
|
21 | 21 | import java.io.FileNotFoundException; |
22 | 22 | import java.io.IOException; |
| 23 | +import java.io.Serializable; |
23 | 24 | import java.lang.ref.WeakReference; |
24 | 25 | import java.math.BigDecimal; |
25 | 26 | import java.math.RoundingMode; |
|
47 | 48 | import javax.xml.parsers.ParserConfigurationException; |
48 | 49 |
|
49 | 50 | import org.apache.ofbiz.base.util.Debug; |
| 51 | +import org.apache.ofbiz.base.util.StringUtil; |
50 | 52 | import org.apache.ofbiz.base.util.UtilGenerics; |
51 | 53 | import org.apache.ofbiz.base.util.UtilMisc; |
| 54 | +import org.apache.ofbiz.base.util.UtilObject; |
52 | 55 | import org.apache.ofbiz.base.util.UtilXml; |
53 | 56 | import org.apache.ofbiz.entity.Delegator; |
54 | 57 | import org.apache.ofbiz.entity.GenericPK; |
@@ -256,11 +259,18 @@ public static Element serializeSingle(Object object, Document document) throws S |
256 | 259 | } |
257 | 260 |
|
258 | 261 | public static Element serializeCustom(Object object, Document document) throws SerializeException { |
259 | | - Debug.logError("Serialization of custom Java objects (cus-obj) is no longer supported. " |
260 | | - + "This feature has been removed for security reasons. Object class: " |
261 | | - + object.getClass().getName(), MODULE); |
262 | | - throw new SerializeException("Serialization of custom Java objects is not supported. " |
263 | | - + "Object class: " + object.getClass().getName()); |
| 262 | + if (object instanceof Serializable) { |
| 263 | + byte[] objBytes = UtilObject.getBytes(object); |
| 264 | + if (objBytes == null) { |
| 265 | + throw new SerializeException("Unable to serialize object; null byte array returned"); |
| 266 | + } |
| 267 | + String byteHex = StringUtil.toHexString(objBytes); |
| 268 | + Element element = document.createElement("cus-obj"); |
| 269 | + // this is hex encoded so does not need to be in a CDATA block |
| 270 | + element.appendChild(document.createTextNode(byteHex)); |
| 271 | + return element; |
| 272 | + } |
| 273 | + throw new SerializeException("Cannot serialize object of class " + object.getClass().getName()); |
264 | 274 | } |
265 | 275 |
|
266 | 276 | public static Element makeElement(String elementName, Object value, Document document) { |
@@ -457,9 +467,17 @@ public static Object deserializeSingle(Element element, Delegator delegator) thr |
457 | 467 | public static Object deserializeCustom(Element element) throws SerializeException { |
458 | 468 | String tagName = element.getLocalName(); |
459 | 469 | if ("cus-obj".equals(tagName)) { |
460 | | - Debug.logError("Deserialization of cus-obj elements is no longer supported. " |
461 | | - + "This feature has been removed for security reasons.", MODULE); |
462 | | - throw new SerializeException("Deserialization of cus-obj elements is not supported."); |
| 470 | + String value = UtilXml.elementValue(element); |
| 471 | + if (value != null) { |
| 472 | + byte[] valueBytes = StringUtil.fromHexString(value); |
| 473 | + if (valueBytes != null) { |
| 474 | + Object obj = UtilObject.getObject(valueBytes); |
| 475 | + if (obj != null) { |
| 476 | + return obj; |
| 477 | + } |
| 478 | + } |
| 479 | + } |
| 480 | + throw new SerializeException("Problem deserializing object from byte array + " + element.getLocalName()); |
463 | 481 | } |
464 | 482 | throw new SerializeException("Cannot deserialize element named " + element.getLocalName()); |
465 | 483 | } |
|
0 commit comments