public void defaultReadObject() { if (serializationMembers.getSerializablePersistentFields(currentType[0]) != null) { readFieldsFromStream(); return; } if (!reader.hasMoreChildren()) { return; } reader.moveDown(); if (!reader.getNodeName().equals(ELEMENT_DEFAULT)) { throw new ConversionException("Expected <" + ELEMENT_DEFAULT + "/> element in readObject() stream"); } while (reader.hasMoreChildren()) { reader.moveDown(); String fieldName = mapper.realMember(currentType[0], reader.getNodeName()); if (mapper.shouldSerializeMember(currentType[0], fieldName)) { String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); final Class type; if (classAttribute != null) { type = mapper.realClass(classAttribute); } else { type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, currentType[0])); } Object value = context.convertAnother(result, type); reflectionProvider.writeField(result, fieldName, value, currentType[0]); } reader.moveUp(); } reader.moveUp(); }
String name = null; Class type = null; while (reader.hasMoreChildren()) { reader.moveDown(); final String elementName = reader.getNodeName(); if (elementName.equals("mimeType")) { mimeType = reader.getValue(); name = reader.getValue(); } else if (elementName.equals("representationClass")) { type = (Class)context.convertAnother(null, Class.class); } else { final ConversionException exception = new ConversionException("Unknown child element"); exception.add("element", reader.getNodeName()); throw exception; throw new ConversionException(ex); } catch (final NullPointerException ex) { throw new ConversionException(ex);
/** * @param solverConfigResource never null, a classpath resource * as defined by {@link ClassLoader#getResource(String)} * @return this */ public XStreamXmlSolverFactory<Solution_> configure(String solverConfigResource) { ClassLoader actualClassLoader = solverConfigContext.determineActualClassLoader(); try (InputStream in = actualClassLoader.getResourceAsStream(solverConfigResource)) { if (in == null) { String errorMessage = "The solverConfigResource (" + solverConfigResource + ") does not exist as a classpath resource in the classLoader (" + actualClassLoader + ")."; if (solverConfigResource.startsWith("/")) { errorMessage += "\nAs from 6.1, a classpath resource should not start with a slash (/)." + " A solverConfigResource now adheres to ClassLoader.getResource(String)." + " Remove the leading slash from the solverConfigResource if you're upgrading from 6.0."; } throw new IllegalArgumentException(errorMessage); } return configure(in); } catch (ConversionException e) { String lineNumber = e.get("line number"); throw new IllegalArgumentException("Unmarshalling of solverConfigResource (" + solverConfigResource + ") fails on line number (" + lineNumber + ")." + (Objects.equals(e.get("required-type"), "java.lang.Class") ? "\n Maybe the classname on line number (" + lineNumber + ") is surrounded by whitespace, which is invalid." : ""), e); } catch (IOException e) { throw new IllegalArgumentException("Reading the solverConfigResource (" + solverConfigResource + ") failed.", e); } }
@Override public Object fromString(final String str) { try { return LocalTime.parse(str); } catch (final DateTimeParseException e) { final ConversionException exception = new ConversionException("Cannot parse value as local time", e); exception.add("value", str); throw exception; } }
public Object convertAnother(Object parent, Class type, Converter converter) { type = mapper.defaultImplementationOf(type); if (converter == null) { converter = converterLookup.lookupConverterForType(type); } else { if (!converter.canConvert(type)) { ConversionException e = new ConversionException( "Explicit selected converter cannot handle type"); e.add("item-type", type.getName()); e.add("converter-type", converter.getClass().getName()); throw e; } } return convert(parent, type, converter); }
public boolean add(Object object) { if (object == null) { boolean containsNull = !map.containsKey(null); map.put(null, null); return containsNull; } Class itemType = object.getClass(); if (keyFieldName != null) { Field field = (Field)fieldCache.get(itemType); if (field == null) { field = reflectionProvider.getField(itemType, keyFieldName); fieldCache.put(itemType, field); } if (field != null) { Object key = Fields.read(field, object); return map.put(key, object) == null; } } else if (object instanceof Map.Entry) { final Map.Entry entry = (Map.Entry)object; return map.put(entry.getKey(), entry.getValue()) == null; } ConversionException exception = new ConversionException("Element is not defined as entry for implicit map"); exception.add("map-type", map.getClass().getName()); exception.add("element-type", object.getClass().getName()); throw exception; }
public Map readFieldsFromStream() { final Map fields = new HashMap(); reader.moveDown(); if (reader.getNodeName().equals(ELEMENT_FIELDS)) { while (reader.hasMoreChildren()) { reader.moveDown(); if (!reader.getNodeName().equals(ELEMENT_FIELD)) { throw new ConversionException("Expected <" + ELEMENT_FIELD + "/> element inside <" + ELEMENT_FIELD + "/>"); String name = reader.getAttribute(ATTRIBUTE_NAME); Class type = mapper.realClass(reader.getAttribute(ATTRIBUTE_CLASS)); Object value = context.convertAnother(result, type); fields.put(name, value); reader.moveUp(); while (reader.hasMoreChildren()) { reader.moveDown(); String name = mapper.realMember(currentType[0], reader.getNodeName()); if (mapper.shouldSerializeMember(currentType[0], name)) { String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); Class type; Object value = context.convertAnother(result, type); fields.put(name, value); throw new ConversionException("Expected <" + ELEMENT_FIELDS + "/> or <" + ELEMENT_DEFAULT + "/> element when calling ObjectInputStream.readFields()");
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); SortedMap sortedMap; TreeMap result; if (reader.getNodeName().equals("comparator")) { String comparatorClass = reader.getAttribute("class"); Comparator comparator = (Comparator) context.convertAnother(null, mapper().realClass(comparatorClass)); sortedMap = new PresortedMap(comparator); result = new TreeMap(comparator); } else if (reader.getNodeName().equals("no-comparator")) { sortedMap = new PresortedMap(); result = new TreeMap(); } else { throw new ConversionException("TreeMap does not contain <comparator> element"); } reader.moveUp(); super.populateMap(reader, context, sortedMap); result.putAll(sortedMap); // // internal optimization will not call comparator return result; }
InvocationHandler handler = null; Class handlerType = null; while (reader.hasMoreChildren()) { reader.moveDown(); String elementName = reader.getNodeName(); if (elementName.equals("interface")) { interfaces.add(mapper.realClass(reader.getValue())); } else if (elementName.equals("handler")) { String attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { handlerType = mapper.realClass(reader.getAttribute(attributeName)); break; throw new ConversionException("No InvocationHandler specified for dynamic proxy"); proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, DUMMY); handler = (InvocationHandler) context.convertAnother(proxy, handlerType); reader.moveUp(); if (HANDLER != null) {
ConversionException exception = new ConversionException("Cannot convert type"); exception.add("source-type", value.getClass().getName()); exception.add("target-type", type.getName()); throw exception; reflectionProvider.writeField(result, attrName, value, classDefiningField); while (reader.hasMoreChildren()) { if (implicitCollectionMapping == null) { field = reflectionProvider.getFieldOrNull(fieldDeclaringClass, fieldName); if (field == null) { final Object key = context.convertAnother( final Object v = context.convertAnother( } else { value = context.convertAnother(result, type); throw new ConversionException("Cannot convert type " + value.getClass().getName() + " to type "
public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) { final SeenFields seenFields = new SeenFields(); Iterator it = reader.getAttributeNames(); if (result instanceof Saveable && context.get("Saveable") == null) context.put("Saveable", result); Object value = converter.fromString(reader.getAttribute(attrAlias)); if (type.isPrimitive()) { type = Primitives.box(type); throw new ConversionException("Cannot convert type " + value.getClass().getName() + " to type " + type.getName()); reflectionProvider.writeField(result, attrName, value, classDefiningField); seenFields.add(classDefiningField, attrName); while (reader.hasMoreChildren()) { reader.moveDown(); final Object value; if (fieldExistsInClass) { Field field = reflectionProvider.getField(result.getClass(),fieldName); value = unmarshalField(context, result, type, field); value = context.convertAnother(result, type);
@SuppressWarnings("unchecked") public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String attributeName = mapper.aliasForSystemAttribute("enum-type"); if (attributeName == null) { throw new ConversionException("No EnumType specified for EnumSet"); } Class enumTypeForSet = mapper.realClass(reader.getAttribute(attributeName)); EnumSet set = EnumSet.noneOf(enumTypeForSet); String[] enumValues = reader.getValue().split(","); for (int i = 0; i < enumValues.length; i++) { String enumValue = enumValues[i]; if(enumValue.length() > 0) { set.add(Enum.valueOf(enumTypeForSet, enumValue)); } } return set; }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String methodName = null; String declaringClassName = null; while((methodName == null || declaringClassName == null) && reader.hasMoreChildren()) { reader.moveDown(); if (reader.getNodeName().equals("name")) { methodName = reader.getValue(); } else if (reader.getNodeName().equals("clazz")) { declaringClassName = reader.getValue(); } reader.moveUp(); } Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName); try { return declaringClass.getDeclaredField(mapper.realMember(declaringClass, methodName)); } catch (NoSuchFieldException e) { throw new ConversionException(e); } } }
String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_SERIALIZATION); if (attributeName != null && !ATTRIBUTE_VALUE_CUSTOM.equals(reader.getAttribute(attributeName))) { throw new ConversionException("Cannot deserialize object with new readObject()/writeObject() methods"); reader.moveDown(); if (!reader.getNodeName().equals(ELEMENT_FIELD)) { throw new ConversionException("Expected <" + ELEMENT_FIELD + "/> element inside <" + ELEMENT_FIELD + "/>"); throw new ConversionException("Expected <" + ELEMENT_FIELDS + "/> or <" + ELEMENT_DEFAULT + "/> element when calling ObjectInputStream.readFields()"); throw new ConversionException("Expected <" + ELEMENT_DEFAULT + "/> element in readObject() stream"); while (reader.hasMoreChildren()) { reader.moveDown(); String nodeName = reader.getNodeName(); if (nodeName.equals(ELEMENT_UNSERIALIZABLE_PARENTS)) { String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); if (classAttribute == null) { currentType[0] = mapper.defaultImplementationOf(mapper.realClass(nodeName)); } else { currentType[0] = mapper.realClass(classAttribute);
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { try { boolean isMethodNotConstructor = context.getRequiredType().equals(Method.class); reader.moveDown(); String declaringClassName = reader.getValue(); Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName); reader.moveUp(); throw new ConversionException(e);
final Iterator it = reader.getAttributeNames(); final ConversionException exception = new ConversionException( "Cannot read field as a single value for object"); exception.add("field", fieldName); exception.add("type", resultType.getName()); throw exception; final ConversionException exception = new ConversionException( "Cannot assign object to type"); exception.add("object type", value.getClass().getName()); exception.add("target type", type.getName()); throw exception; classDefiningField, fieldName); if (fieldName == null || field == null) { final ConversionException exception = new ConversionException( "Cannot assign value to field of type"); exception.add("element", reader.getNodeName()); exception.add("field", fieldName); exception.add("target type", context.getRequiredType().getName()); throw exception; final ConversionException exception = new ConversionException( "Cannot assign object to type"); exception.add("object type", value.getClass().getName()); exception.add("target type", type.getName()); throw exception;
public void visit(String fieldName, Class type, Class definedIn, Object value) { if (!mapper.shouldSerializeMember(definedIn, fieldName)) { return; && !mapper.shouldSerializeMember(lookupType, fieldName)) { lookupType = definedIn; fieldName, reflectionProvider.getField(lookupType, fieldName)); SingleValueConverter converter = mapper.getConverterFromItemType( fieldName, type, definedIn); if (converter != null) { if (writtenAttributes.contains(fieldName)) { ConversionException exception = new ConversionException("Cannot write field as attribute for object, attribute name already in use"); exception.add("field-name", fieldName); exception.add("object-type", sourceType.getName()); throw exception;
public Object fromString(String str) { try { return ctor.newInstance(new Object[] {str}); } catch (InstantiationException e) { throw new ConversionException("Unable to instantiate single String param constructor", e); } catch (IllegalAccessException e) { throw new ObjectAccessException("Unable to access single String param constructor", e); } catch (InvocationTargetException e) { throw new ConversionException("Unable to target single String param constructor", e.getTargetException()); } } }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) { Class qnameClass = unmarshallingContext.getRequiredType(); if (!canConvert(qnameClass)) { throw new ConversionException("Unexpected type in unmarshal: " + qnameClass.getName()); } String qnameString = reader.getValue(); try { Method method = qnameClass.getMethod("valueOf", new Class[]{String.class}); Object qname = method.invoke(null, new Object[] { qnameString }); return qname; } catch (Exception e) { throw new ConversionException("Unable to convert value to a qname: " + qnameString, e); } } }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { throw new ConversionException("Refusing to unmarshal " + reader.getNodeName() + " for security reasons; see https://jenkins.io/redirect/class-filter/"); }