Refine search
/** * Convenience method for constructing {@link JavaType} for given JDK * type (usually {@link java.lang.Class}) */ public JavaType constructType(Type type) { if (type == null) { return null; } return getTypeFactory().constructType(type); }
/** * @since 2.9 */ public <T> T reportBadDefinition(Class<?> type, String msg) throws JsonMappingException { return reportBadDefinition(constructType(type), msg); }
public ObjectIdResolver objectIdResolverInstance(Annotated annotated, ObjectIdInfo objectIdInfo) { Class<? extends ObjectIdResolver> implClass = objectIdInfo.getResolverType(); final MapperConfig<?> config = getConfig(); HandlerInstantiator hi = config.getHandlerInstantiator(); ObjectIdResolver resolver = (hi == null) ? null : hi.resolverIdGeneratorInstance(config, annotated, implClass); if (resolver == null) { resolver = ClassUtil.createInstance(implClass, config.canOverrideAccessModifiers()); } return resolver; }
JavaType t = getTypeFactory().constructFromCanonical(subClass); if (t.isTypeOrSubTypeOf(baseType.getRawClass())) { return t; Class<?> cls; try { cls = getTypeFactory().findClass(subClass); } catch (ClassNotFoundException e) { // let caller handle this problem return null; } catch (Exception e) { throw invalidTypeIdException(baseType, subClass, String.format( "problem: (%s) %s", e.getClass().getName(), ClassUtil.exceptionMessage(e))); return getTypeFactory().constructSpecializedType(baseType, cls); throw invalidTypeIdException(baseType, subClass, "Not a subtype");
/** * Convenience method for constructing subtypes, retaining generic * type parameter (if any) */ public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass) { // simple optimization to avoid costly introspection if type-erased type does NOT differ if (baseType.getRawClass() == subclass) { return baseType; } return getConfig().constructSpecializedType(baseType, subclass); }
@Override public JavaType typeFromId(DatabindContext context, String id) { return context.constructType(ServiceInstanceEntity.class); }
/** * Convenience method for accessing serialization view in use (if any); equivalent to: *<pre> * getConfig().canOverrideAccessModifiers(); *</pre> */ public final boolean canOverrideAccessModifiers() { return getConfig().canOverrideAccessModifiers(); }
@Override public JavaType typeFromId(DatabindContext context, String id) throws IOException { DeserializationConfig config = (DeserializationConfig) context.getConfig(); JavaType result = delegate.typeFromId(context, id); String className = result.getRawClass().getName(); if (isWhitelisted(className)) { return delegate.typeFromId(context, id); } boolean isExplicitMixin = config.findMixInClassFor(result.getRawClass()) != null; if (isExplicitMixin) { return result; } JacksonAnnotation jacksonAnnotation = AnnotationUtils.findAnnotation(result.getRawClass(), JacksonAnnotation.class); if (jacksonAnnotation != null) { return result; } throw new IllegalArgumentException("The class with " + id + " and name of " + className + " is not whitelisted. " + "If you believe this class is safe to deserialize, please provide an explicit mapping using Jackson annotations or by providing a Mixin. " + "If the serialization is only done by a trusted source, you can also enable default typing. " + "See https://github.com/spring-projects/spring-security/issues/4370 for details"); }
public static EcoreTypeFactory getTypeFactory(DatabindContext ctxt) { EcoreTypeFactory factory = (EcoreTypeFactory) ctxt.getAttribute(Internals.TYPE_FACTORY); if (factory == null) { ctxt.setAttribute(Internals.TYPE_FACTORY, factory = new EcoreTypeFactory()); } return factory; }
public static EReference getReference(DatabindContext ctxt) { try { return (EReference) ctxt.getAttribute(Internals.CURRENT_FEATURE); } catch (ClassCastException e) { return null; } }
/** * @since 2.9 */ protected String _desc(String desc) { if (desc == null) { return "[N/A]"; } // !!! should we quote it? (in case there are control chars, linefeeds) return _truncate(desc); } }
/** * Convenience method for constructing subtypes, retaining generic * type parameter (if any) */ public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass) { // simple optimization to avoid costly introspection if type-erased type does NOT differ if (baseType.getRawClass() == subclass) { return baseType; } return getConfig().constructSpecializedType(baseType, subclass); }
JavaType t = getTypeFactory().constructFromCanonical(subClass); if (t.isTypeOrSubTypeOf(baseType.getRawClass())) { return t; Class<?> cls; try { cls = getTypeFactory().findClass(subClass); } catch (ClassNotFoundException e) { // let caller handle this problem return null; } catch (Exception e) { throw invalidTypeIdException(baseType, subClass, String.format( "problem: (%s) %s", e.getClass().getName(), ClassUtil.exceptionMessage(e))); return getTypeFactory().constructSpecializedType(baseType, cls); throw invalidTypeIdException(baseType, subClass, "Not a subtype");
switch (id) { case "regex.Star": return context.constructType(iguana.regex.Star.class); case "regex.Plus": return context.constructType(iguana.regex.Plus.class); case "regex.Alt": return context.constructType(iguana.regex.Alt.class); case "regex.Opt": return context.constructType(iguana.regex.Opt.class); case "IfThenElseExpr": return context.constructType(Expression.IfThenElse.class); try { Class<?> clazz = Class.forName(packageName + id); javaType = context.constructType(clazz); break; } catch (ClassNotFoundException e) {
/** * Convenience method for accessing serialization view in use (if any); equivalent to: *<pre> * getConfig().canOverrideAccessModifiers(); *</pre> */ public final boolean canOverrideAccessModifiers() { return getConfig().canOverrideAccessModifiers(); }
@Override public JavaType typeFromId(DatabindContext context, String id) throws IOException { DeserializationConfig config = (DeserializationConfig) context.getConfig(); JavaType result = delegate.typeFromId(context, id); String className = result.getRawClass().getName(); if (isWhitelisted(className)) { return delegate.typeFromId(context, id); } boolean isExplicitMixin = config.findMixInClassFor(result.getRawClass()) != null; if (isExplicitMixin) { return result; } JacksonAnnotation jacksonAnnotation = AnnotationUtils.findAnnotation(result.getRawClass(), JacksonAnnotation.class); if (jacksonAnnotation != null) { return result; } throw new IllegalArgumentException("The class with " + id + " and name of " + className + " is not whitelisted. " + "If you believe this class is safe to deserialize, please provide an explicit mapping using Jackson annotations or by providing a Mixin. " + "If the serialization is only done by a trusted source, you can also enable default typing. " + "See https://github.com/spring-projects/spring-security/issues/4370 for details"); }
public static ReferenceEntries getEntries(DatabindContext ctxt) { try { return (ReferenceEntries) ctxt.getAttribute(Internals.REFERENCE_ENTRIES); } catch (ClassCastException e) { ReferenceEntries entries = new ReferenceEntries(); ctxt.setAttribute(Internals.REFERENCE_ENTRIES, entries); return entries; } }
public static EDataType getDataType(DatabindContext ctxt) { try { return (EDataType) ctxt.getAttribute(Internals.CURRENT_DATATYPE); } catch (ClassCastException e) { return null; } }