Java Code Examples for com.fasterxml.jackson.databind.deser.std.StringDeserializer

The following examples show how to use com.fasterxml.jackson.databind.deser.std.StringDeserializer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: youran   Source File: JacksonXSSDeserializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    if (property != null) {
        IgnoreXSS annotation = property.getAnnotation(IgnoreXSS.class);
        if (annotation != null) {
            return StringDeserializer.instance;
        }
    }
    return this;
}
 
Example 2
Source Project: youran   Source File: JacksonXSSDeserializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    String value = StringDeserializer.instance.deserialize(p, ctxt);
    return XSSUtil.clean(value);
}
 
Example 3
Source Project: youran   Source File: JacksonXSSDeserializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
    String value = StringDeserializer.instance.deserializeWithType(jp, ctxt, typeDeserializer);
    return XSSUtil.clean(value);
}
 
Example 4
Source Project: youran   Source File: JacksonXSSDeserializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCachable() {
    return StringDeserializer.instance.isCachable();
}
 
Example 5
public TrimmingStringDeserializer() {
    super(String.class);
    this.stdDeserializer = new StringDeserializer();
}
 
Example 6
@Override
public void runConversion(int numberOfAttributes, int lengthOfAttribute) {
    int assignmentsTotal, progress = 0;
    assignmentsConverted = submissionsConverted = submissionsFailed = assignmentsFailed = 0;

    SimpleModule module = new SimpleModule().addDeserializer(String.class, new StdDeserializer<String>(String.class) {
        @Override
        public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
            String str = StringDeserializer.instance.deserialize(p, ctxt);
            if (StringUtils.isBlank(str)) return null;
            return str;
        }
    });

    // woodstox xml parser defaults we don't allow values smaller than the default
    if (numberOfAttributes < ReaderConfig.DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT) numberOfAttributes = ReaderConfig.DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT;
    if (lengthOfAttribute < ReaderConfig.DEFAULT_MAX_ATTRIBUTE_LENGTH) lengthOfAttribute = ReaderConfig.DEFAULT_MAX_ATTRIBUTE_LENGTH;

    log.info("<===== Assignments conversion xml parser limits: number of attributes={}, attribute size={} =====>", numberOfAttributes, lengthOfAttribute);

    XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
    xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTES_PER_ELEMENT, numberOfAttributes);
    xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, lengthOfAttribute);
    xmlMapper = new XmlMapper(xmlInputFactory);
    xmlMapper.registerModule(new Jdk8Module());
    xmlMapper.registerModule(module);

    String configValue = "org.sakaiproject.assignment.api.model.Assignment,org.sakaiproject.assignment.api.model.AssignmentSubmission";
    String currentValue = serverConfigurationService.getConfig(AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES, null);
    if (StringUtils.isNotBlank(currentValue)) {
        configValue = configValue + "," + currentValue;
    }
    ServerConfigurationService.ConfigItem configItem = BasicConfigItem.makeConfigItem(
            AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES,
            configValue,
            AssignmentConversionServiceImpl.class.getName(),
            true);
    serverConfigurationService.registerConfigItem(configItem);

    List<String> preAssignments = dataProvider.fetchAssignmentsToConvert();
    List<String> postAssignments = assignmentRepository.findAllAssignmentIds();
    List<String> convertAssignments = new ArrayList<>(preAssignments);
    convertAssignments.removeAll(postAssignments);
    assignmentsTotal = convertAssignments.size();

    log.info("<===== Assignments pre 12 [{}] and post 12 [{}] to convert {} =====>", preAssignments.size(), postAssignments.size(), assignmentsTotal);

    for (String assignmentId : convertAssignments) {
        try {
            convert(assignmentId);
        } catch (Exception e) {
            log.warn("Assignment conversion exception for {}", assignmentId, e);
        }
        int percent = new Double(((assignmentsConverted + assignmentsFailed) / (double) assignmentsTotal) * 100).intValue();
        if (progress != percent) {
            progress = percent;
            log.info("<===== Assignments conversion completed {}% =====>", percent);
        }
    }

    configItem = BasicConfigItem.makeConfigItem(
            AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES,
            StringUtils.trimToEmpty(currentValue),
            AssignmentConversionServiceImpl.class.getName());
    serverConfigurationService.registerConfigItem(configItem);

    log.info("<===== Assignments converted {} =====>", assignmentsConverted);
    log.info("<===== Submissions converted {} =====>", submissionsConverted);
    log.info("<===== Assignments that failed to be converted {} =====>", assignmentsFailed);
    log.info("<===== Submissions that failed to be converted {} =====>", submissionsFailed);
}
 
Example 7
@Override
public void runConversion(int numberOfAttributes, int lengthOfAttribute) {
    int assignmentsTotal, progress = 0;
    assignmentsConverted = submissionsConverted = submissionsFailed = assignmentsFailed = 0;

    SimpleModule module = new SimpleModule().addDeserializer(String.class, new StdDeserializer<String>(String.class) {
        @Override
        public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
            String str = StringDeserializer.instance.deserialize(p, ctxt);
            if (StringUtils.isBlank(str)) return null;
            return str;
        }
    });

    // woodstox xml parser defaults we don't allow values smaller than the default
    if (numberOfAttributes < ReaderConfig.DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT) numberOfAttributes = ReaderConfig.DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT;
    if (lengthOfAttribute < ReaderConfig.DEFAULT_MAX_ATTRIBUTE_LENGTH) lengthOfAttribute = ReaderConfig.DEFAULT_MAX_ATTRIBUTE_LENGTH;

    log.info("<===== Assignments conversion xml parser limits: number of attributes={}, attribute size={} =====>", numberOfAttributes, lengthOfAttribute);

    XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
    xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTES_PER_ELEMENT, numberOfAttributes);
    xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, lengthOfAttribute);
    xmlMapper = new XmlMapper(xmlInputFactory);
    xmlMapper.registerModule(new Jdk8Module());
    xmlMapper.registerModule(module);

    String configValue = "org.sakaiproject.assignment.api.model.Assignment,org.sakaiproject.assignment.api.model.AssignmentSubmission";
    String currentValue = serverConfigurationService.getConfig(AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES, null);
    if (StringUtils.isNotBlank(currentValue)) {
        configValue = configValue + "," + currentValue;
    }
    ServerConfigurationService.ConfigItem configItem = BasicConfigItem.makeConfigItem(
            AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES,
            configValue,
            AssignmentConversionServiceImpl.class.getName(),
            true);
    serverConfigurationService.registerConfigItem(configItem);

    List<String> preAssignments = dataProvider.fetchAssignmentsToConvert();
    List<String> postAssignments = assignmentRepository.findAllAssignmentIds();
    List<String> convertAssignments = new ArrayList<>(preAssignments);
    convertAssignments.removeAll(postAssignments);
    assignmentsTotal = convertAssignments.size();

    log.info("<===== Assignments pre 12 [{}] and post 12 [{}] to convert {} =====>", preAssignments.size(), postAssignments.size(), assignmentsTotal);

    for (String assignmentId : convertAssignments) {
        try {
            convert(assignmentId);
        } catch (Exception e) {
            log.warn("Assignment conversion exception for {}", assignmentId, e);
        }
        int percent = new Double(((assignmentsConverted + assignmentsFailed) / (double) assignmentsTotal) * 100).intValue();
        if (progress != percent) {
            progress = percent;
            log.info("<===== Assignments conversion completed {}% =====>", percent);
        }
    }

    configItem = BasicConfigItem.makeConfigItem(
            AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES,
            StringUtils.trimToEmpty(currentValue),
            AssignmentConversionServiceImpl.class.getName());
    serverConfigurationService.registerConfigItem(configItem);

    log.info("<===== Assignments converted {} =====>", assignmentsConverted);
    log.info("<===== Submissions converted {} =====>", submissionsConverted);
    log.info("<===== Assignments that failed to be converted {} =====>", assignmentsFailed);
    log.info("<===== Submissions that failed to be converted {} =====>", submissionsFailed);
}