private T parseInner()

in juneau-core/juneau-marshall/src/main/java/org/apache/juneau/oapi/OpenApiParserSession.java [266:505]


	private<T> T parseInner(HttpPartType partType, HttpPartSchema schema, String in, ClassMeta<T> type) throws SchemaValidationException, ParseException {
		schema.validateInput(in);
		if (in == null || "null".equals(in)) {
			if (schema.getDefault() == null)
				return null;
			in = schema.getDefault();
		} else {

			ObjectSwap<T,Object> swap = (ObjectSwap<T,Object>)type.getSwap(this);
			BuilderSwap<T,Object> builder = (BuilderSwap<T,Object>)type.getBuilderSwap(this);
			ClassMeta<?> sType = null;
			if (builder != null)
				sType = builder.getBuilderClassMeta(this);
			else if (swap != null)
				sType = swap.getSwapClassMeta(this);
			else
				sType = type;

			if (sType.isOptional())
				return (T)optional(parseInner(partType, schema, in, sType.getElementType()));

			HttpPartDataType t = schema.getType(sType);
			if (partType == null)
				partType = HttpPartType.OTHER;

			HttpPartFormat f = schema.getFormat(sType);
			if (f == HttpPartFormat.NO_FORMAT)
				f = ctx.getFormat();

			if (t == STRING) {
				if (sType.isObject()) {
					if (f == BYTE)
						return toType(base64Decode(in), type);
					if (f == DATE || f == DATE_TIME)
						return toType(parseIsoCalendar(in), type);
					if (f == BINARY)
						return toType(fromHex(in), type);
					if (f == BINARY_SPACED)
						return toType(fromSpacedHex(in), type);
					if (f == HttpPartFormat.UON)
						return super.parse(partType, schema, in, type);
					return toType(in, type);
				}
				if (f == BYTE)
					return toType(base64Decode(in), type);
				if (f == DATE) {
					try {
						if (type.isCalendar())
							return toType(TemporalCalendarSwap.IsoDate.DEFAULT.unswap(this, in, type), type);
						if (type.isDate())
							return toType(TemporalDateSwap.IsoDate.DEFAULT.unswap(this, in, type), type);
						if (type.isTemporal())
							return toType(TemporalSwap.IsoDate.DEFAULT.unswap(this, in, type), type);
						return toType(in, type);
					} catch (Exception e) {
						throw new ParseException(e);
					}
				}
				if (f == DATE_TIME) {
					try {
						if (type.isCalendar())
							return toType(TemporalCalendarSwap.IsoDateTime.DEFAULT.unswap(this, in, type), type);
						if (type.isDate())
							return toType(TemporalDateSwap.IsoDateTime.DEFAULT.unswap(this, in, type), type);
						if (type.isTemporal())
							return toType(TemporalSwap.IsoDateTime.DEFAULT.unswap(this, in, type), type);
						return toType(in, type);
					} catch (Exception e) {
						throw new ParseException(e);
					}
				}
				if (f == BINARY)
					return toType(fromHex(in), type);
				if (f == BINARY_SPACED)
					return toType(fromSpacedHex(in), type);
				if (f == HttpPartFormat.UON)
					return super.parse(partType, schema, in, type);
				return toType(in, type);

			} else if (t == BOOLEAN) {
				if (type.isObject())
					type = (ClassMeta<T>)CM_Boolean;
				if (type.isBoolean())
					return super.parse(partType, schema, in, type);
				return toType(super.parse(partType, schema, in, CM_Boolean), type);

			} else if (t == INTEGER) {
				if (type.isObject()) {
					if (f == INT64)
						type = (ClassMeta<T>)CM_Long;
					else
						type = (ClassMeta<T>)CM_Integer;
				}
				if (type.isNumber())
					return super.parse(partType, schema, in, type);
				return toType(super.parse(partType, schema, in, CM_Integer), type);

			} else if (t == NUMBER) {
				if (type.isObject()) {
					if (f == DOUBLE)
						type = (ClassMeta<T>)CM_Double;
					else
						type = (ClassMeta<T>)CM_Float;
				}
				if (type.isNumber())
					return super.parse(partType, schema, in, type);
				return toType(super.parse(partType, schema, in, CM_Double), type);

			} else if (t == ARRAY) {

				HttpPartCollectionFormat cf = schema.getCollectionFormat();
				if (cf == HttpPartCollectionFormat.NO_COLLECTION_FORMAT)
					cf = ctx.getCollectionFormat();

				if (cf == HttpPartCollectionFormat.UONC)
					return super.parse(partType, schema, in, type);

				if (type.isObject())
					type = (ClassMeta<T>)CM_JsonList;

				ClassMeta<?> eType = type.isObject() ? string() : type.getElementType();
				if (eType == null)
					eType = schema.getParsedType().getElementType();
				if (eType == null)
					eType = string();

				String[] ss = {};

				if (cf == MULTI)
					ss = new String[]{in};
				else if (cf == CSV)
					ss = split(in, ',');
				else if (cf == PIPES)
					ss = split(in, '|');
				else if (cf == SSV)
					ss = splitQuoted(in);
				else if (cf == TSV)
					ss = split(in, '\t');
				else if (cf == HttpPartCollectionFormat.UONC)
					return super.parse(partType, null, in, type);
				else if (cf == NO_COLLECTION_FORMAT) {
					if (firstNonWhitespaceChar(in) == '@' && lastNonWhitespaceChar(in) == ')')
						return super.parse(partType, null, in, type);
					ss = split(in, ',');
				}

				HttpPartSchema items = schema.getItems();
				if (items == null)
					items = HttpPartSchema.DEFAULT;
				Object o = Array.newInstance(eType.getInnerClass(), ss.length);
				for (int i = 0; i < ss.length; i++)
					Array.set(o, i, parse(partType, items, ss[i], eType));
				if (type.hasMutaterFrom(schema.getParsedType()) || schema.getParsedType().hasMutaterTo(type))
					return toType(toType(o, schema.getParsedType()), type);
				return toType(o, type);

			} else if (t == OBJECT) {

				HttpPartCollectionFormat cf = schema.getCollectionFormat();
				if (cf == HttpPartCollectionFormat.NO_COLLECTION_FORMAT)
					cf = ctx.getCollectionFormat();

				if (cf == HttpPartCollectionFormat.UONC)
					return super.parse(partType, schema, in, type);

				if (type.isObject())
					type = (ClassMeta<T>)CM_JsonMap;

				if (! type.isMapOrBean())
					throw new ParseException("Invalid type {0} for part type OBJECT.", type);

				String[] ss = {};

				if (cf == MULTI)
					ss = new String[]{in};
				else if (cf == CSV)
					ss = split(in, ',');
				else if (cf == PIPES)
					ss = split(in, '|');
				else if (cf == SSV)
					ss = splitQuoted(in);
				else if (cf == TSV)
					ss = split(in, '\t');
				else if (cf == HttpPartCollectionFormat.UONC)
					return super.parse(partType, null, in, type);
				else if (cf == NO_COLLECTION_FORMAT) {
					if (firstNonWhitespaceChar(in) == '@' && lastNonWhitespaceChar(in) == ')')
						return super.parse(partType, null, in, type);
					ss = split(in, ',');
				}

				if (type.isBean()) {
					BeanMap<T> m = ctx.getBeanContext().newBeanMap(type.getInnerClass());
					for (String s : ss) {
						String[] kv = split(s, '=', 2);
						if (kv.length != 2)
							throw new ParseException("Invalid input {0} for part type OBJECT.", in);
						String key = kv[0], value = kv[1];
						BeanPropertyMeta bpm = m.getPropertyMeta(key);
						if (bpm == null && ! isIgnoreUnknownBeanProperties())
							throw new ParseException("Invalid input {0} for part type OBJECT.  Cannot find property {1}", in, key);
						m.put(key, parse(partType, schema.getProperty(key), value, ((ClassMeta<T>)(bpm == null ? object() : bpm.getClassMeta()))));
					}
					return m.getBean();
				}

				ClassMeta<?> eType = type.isObject() ? string() : type.getValueType();
				if (eType == null)
					eType = schema.getParsedType().getValueType();
				if (eType == null)
					eType = string();

				try {
					Map<String,Object> m = (Map<String,Object>)type.newInstance();
					if (m == null)
						m = JsonMap.create();

					for (String s : ss) {
						String[] kv = split(s, '=', 2);
						if (kv.length != 2)
							throw new ParseException("Invalid input {0} for part type OBJECT.", in);
						String key = kv[0], value = kv[1];
						m.put(key, parse(partType, schema.getProperty(key), value, eType));
					}
					return (T)m;
				} catch (ExecutableException e) {
					throw new ParseException(e);
				}

			} else if (t == FILE) {
				throw new ParseException("File part not supported.");

			} else if (t == NO_TYPE) {
				// This should never be returned by HttpPartSchema.getType(ClassMeta).
				throw new ParseException("Invalid type.");
			}
		}

		return super.parse(partType, schema, in, type);
	}