Package flexjson

Examples of flexjson.JSONException


        Object source = context.getSource();
        if( source instanceof Map ) {
            Map map = (Map)source;
            return types.get( map.get( fieldname ) );
        } else {
            throw new JSONException( String.format("%s: Don't know how to locate types for source %s using fieldname %s.  TypeLocator requires the source object be a java.util.Map in order to work.", context.getCurrentPath(), source.getClass(), fieldname ) );
        }
    }
View Full Code Here


                path.pop();

            }
            getContext().writeCloseObject();
        } catch( Exception ex ) {
            throw new JSONException(String.format("%s: Error while trying to serialize.", path), ex);
        }
    }
View Full Code Here

    public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) {
        try {
            return getFormatter().parse(value.toString());
        } catch (ParseException e) {
            throw new JSONException(String.format( "%s: Failed to parse %s with %s pattern.", context.getCurrentPath(), value, dateFormat ), e );
        }
    }
View Full Code Here

                        return format.parse( value.toString() );
                    } catch (ParseException e) {
                        // try next format
                    }
                }
                throw new JSONException( String.format("%s:  Parsing date %s was not recognized as a date format", context.getCurrentPath(), value ) );
            }
        } catch (IllegalAccessException e) {
            throw new JSONException( String.format("%s:  Error encountered trying to instantiate %s", context.getCurrentPath(), ((Class)targetType).getName() ), e);
        } catch (InstantiationException e) {
            throw new JSONException( String.format("%s:  Error encountered trying to instantiate %s.  Make sure there is a public constructor that accepts a single Long.", context.getCurrentPath(), ((Class)targetType).getName() ), e);
        } catch (InvocationTargetException e) {
            throw new JSONException( String.format("%s:  Error encountered trying to instantiate %s.  Make sure there is a public constructor that accepts a single Long.", context.getCurrentPath(), ((Class)targetType).getName() ), e);
        }
    }
View Full Code Here

public class EnumObjectFactory implements ObjectFactory {
    public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) {
        if( value instanceof String ) {
            return Enum.valueOf( (Class)targetType, value.toString() );
        } else {
            throw new JSONException( String.format("%s:  Don't know how to convert %s to enumerated constant of %s", context.getCurrentPath(), value, targetType ) );
        }
    }
View Full Code Here

    public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) {
        try {
            Object target = instantiate( targetClass );
            return context.bindIntoObject( (Map)value, target, targetType );
        } catch (InstantiationException e) {
            throw new JSONException(context.getCurrentPath() + ":There was an exception trying to instantiate an instance of " + targetClass.getName(), e );
        } catch (IllegalAccessException e) {
            throw new JSONException(context.getCurrentPath() + ":There was an exception trying to instantiate an instance of " + targetClass.getName(), e );
        } catch (InvocationTargetException e) {
            throw new JSONException(context.getCurrentPath() + ":There was an exception trying to instantiate an instance of " + targetClass.getName(), e );
        } catch (NoSuchMethodException e) {
            throw new JSONException(context.getCurrentPath() + ": " + targetClass.getName() + " lacks a no argument constructor.  Flexjson will instantiate any protected, private, or public no-arg constructor.", e );
        }
    }
View Full Code Here

    public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) {
        List list = (List) value;
        context.getCurrentPath().enqueue("values");
        try {
            Class memberClass = targetClass.getComponentType() != null ? targetClass.getComponentType() : context.findClassAtPath( context.getCurrentPath() );
            if( memberClass == null ) throw new JSONException("Missing concrete class for array.  You might require a use() method.");
            Object array = Array.newInstance( memberClass, list.size() );
            for( int i = 0; i < list.size(); i++ ) {
                Object v = context.bind( list.get(i), memberClass );
                Array.set( array, i, v );
            }
            return array;
        } catch( ClassNotFoundException ex ) {
            throw new JSONException( String.format("%s: Could not find class %s", context.getCurrentPath(), ex.getMessage() ), ex );
        } finally {
            context.getCurrentPath().pop();
        }
    }
View Full Code Here

                }
            } else {
                return null;
            }
        } catch( ClassNotFoundException ex )  {
            throw new JSONException( String.format("%s: Could not find class %s", context.getCurrentPath(), ex.getMessage() ), ex);
        } catch (IllegalAccessException e) {
            throw new JSONException( String.format("%s: Could not instantiate class %s", context.getCurrentPath(), clazz.getName() ), e );
        } catch (InstantiationException e) {
            throw new JSONException( String.format("%s: Problem while instantiating class %s", context.getCurrentPath(), clazz.getName() ), e );
        } catch (NoSuchMethodException e) {
            throw new JSONException( String.format("%s: Could not find a no-arg constructor for %s", context.getCurrentPath(), clazz.getName() ), e );
        } catch (InvocationTargetException e) {
            throw new JSONException( String.format("%s: Problem while invoking the no-arg constructor for %s", context.getCurrentPath(), clazz.getName() ), e );
        }
    }
View Full Code Here

        return null;
      }
    }
    catch (ClassNotFoundException ex)
    {
      throw new JSONException(String.format("%s: Could not find class %s", context.getCurrentPath(), ex.getMessage()), ex);
    }
    catch (IllegalAccessException e)
    {
      throw new JSONException(String.format("%s: Could not instantiate class %s", context.getCurrentPath(), clazz.getName()), e);
    }
    catch (InstantiationException e)
    {
      throw new JSONException(String.format("%s: Problem while instantiating class %s", context.getCurrentPath(), clazz.getName()), e);
    }
    catch (NoSuchMethodException e)
    {
      throw new JSONException(String.format("%s: Could not find a no-arg constructor for %s", context.getCurrentPath(), clazz.getName()), e);
    }
    catch (InvocationTargetException e)
    {
      throw new JSONException(String.format("%s: Problem while invoking the no-arg constructor for %s", context.getCurrentPath(), clazz.getName()), e);
    }
  }
View Full Code Here

      Map map= (Map) source;
      return types.get(map.get(fieldname));
    }
    else
    {
      throw new JSONException(String.format("%s: Don't know how to locate types for source %s using fieldname %s.  TypeLocator requires the source object be a java.util.Map in order to work.", context.getCurrentPath(), source.getClass(), fieldname));
    }
  }
View Full Code Here

TOP

Related Classes of flexjson.JSONException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.