Skip to content

GenericConvert/Standard/Primitive should be GenericConvertValue aware #3

@PicoCreator

Description

@PicoCreator

NOTE : This is an issue specifically for JavaCommons-core : https://github.com/picoded/JavaCommons-core

GenericConvertValue introduced into core package, creates a whole set of unexpected behaviour when used with GenericConvert library, where it resorts to the fallback method of converting it into a giant JSON string (for example).

Point is, GenericConvert should defer to the GenericConvertValue implementation where possible.

For example the following changes should be done for toString()

original

	public static String toString(Object input, Object fallbck) {
		if (input == null) {
			if (fallbck == null) {
				return null;
			}
			return toString(fallbck, null);
		}

		// Output as string directly
		if (input instanceof String) {
			return input.toString();
		}
		
		return ConvertJSON.fromObject(input);
	}

to the following

	public static String toString(Object input, Object fallbck) {
		if (input == null) {
			if (fallbck == null) {
				return null;
			}
			return toString(fallbck, null);
		}

		// GenericConvertValue optimization
		if( input instanceof GenericConvertValue ) {
			return toString( ((GenericConvertValue)input).getString(), fallbck );
		}
		
		// Output as string directly
		if (input instanceof String) {
			return input.toString();
		}
		
		return ConvertJSON.fromObject(input);
	}

This changes need to apply to ALL generic convert function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions