class UrlFormFormat extends RepresentationFormat {

    @Override
    public Map<String, Object> readMap( final String input, String... requiredKeys ) throws BadInputException
    {
        HashMap<String, Object> result = new HashMap<>();
        if ( input.isEmpty() )
        {
            return result;
        }

        for ( String pair : input.split( "&" ) )
        {
            String[] fields = pair.split( "=" );
            String key;
            String value;

            try
            {
                String charset = StandardCharsets.UTF_8.name();
                key = ensureThatKeyDoesNotHavePhPStyleParenthesesAtTheEnd( URLDecoder.decode( fields[0], charset ) );
                value = URLDecoder.decode( fields[1], charset );
            }
            catch ( UnsupportedEncodingException e )
            {
                throw new BadInputException( e );
            }

            Object old = result.get( key );
            if ( old == null )
            {
                result.put( key, value );
            }
            else
            {
                List<Object> list;
                if ( old instanceof List<?> )
                {
                    list = (List<Object>) old;
                }
                else
                {
                    list = new ArrayList<>();
                    result.put( key, list );
                    list.add( old );
                }
                list.add( value );
            }
        }

        return DefaultFormat.validateKeys( result, requiredKeys );
    }

    public  UrlFormFormat();

}