IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

SpringBatch 4.X custom serialisation


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 716
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 716
    Par défaut SpringBatch 4.X custom serialisation
    Bonjour

    J'essaye en Spring Batch 4 d'implementer un custom serialisze comme ceci san succes.
    J"ai besoin de gerer les deux modes de serialisation pendannt un certains temps.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
     
     <?xml version = "1.0" encoding = "UTF-8" ?  >
         < beans xmlns = "http://www.springframework.org/schema/beans" xmlns : xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns : jdbc = "http://www.springframework.org/schema/jdbc" xmlns: batch = "http://www.springframework.org/schema/batch"
        xsi: schemaLocation = "http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" >
     
         <!--initialize spring batch technical tables-- >
         <jdbc:initialize-database enabled = "true" ignore - failures = "ALL" >
    		<jdbc:script location = "classpath:${batch.dataSource.metadata.schema.create}" />
         </jdbc:initialize-database>
     
         < batch: job - repository
        id = "jobRepository"
        isolation - level - for  - create = "READ_COMMITTED"
            serializer = "xsExecutionContext"
            transaction - manager = "transactionManager" /  >
     
        <bean id = "xsExecutionContext"
            class = "batch.launch.XStreamOrJackson2ExecutionContextSerializer" >
        </bean>
     
    </beans>
     
            ___________________
     
    package batch.launch;
     
    import java.io.BufferedInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Map;
    import com.fasterxml.jackson.core.JsonProcessingException;
    import org.springframework.batch.core.repository.ExecutionContextSerializer;
    import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer;
    import org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer;
     
    /**
     * Enables Spring Batch 4 to read both ExecutionContext entries written by ealier versions and the Spring 5 format. Entries are
     * written in Spring 5 format.
     */
     @ SuppressWarnings(“deprecation”)
    class XStreamOrJackson2ExecutionContextSerializer implements ExecutionContextSerializer {
        private final XStreamExecutionContextStringSerializer xStream = new XStreamExecutionContextStringSerializer();
        private final Jackson2ExecutionContextStringSerializer jackson = new Jackson2ExecutionContextStringSerializer();
     
        public XStreamOrJackson2ExecutionContextSerializer()throws Exception {
            xStream.afterPropertiesSet();
        }
     
        // The caller closes the stream; and the decoration by ensureMarkSupported does not need any cleanup.
         @ SuppressWarnings(“resource”)
         @ Override
        public Map < String,
        Object > deserialize(InputStream inputStream)throws IOException {
            InputStream repeatableInputStream = ensureMarkSupported(inputStream);
            repeatableInputStream.mark(Integer.MAX_VALUE);
     
            try {
                return jackson.deserialize(repeatableInputStream);
            } catch (JsonProcessingException e) {
                repeatableInputStream.reset();
                return xStream.deserialize(repeatableInputStream);
            }
        }
     
        private static InputStream ensureMarkSupported(InputStream in) {
            return in.markSupported() ? in : new BufferedInputStream(in);
        }
     
         @ Override
        public void serialize(Map < String, Object > object, OutputStream outputStream)throws IOException {
            jackson.serialize(object, outputStream);
        }
    }
    Ou est mon erreur ?
    Merci

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 716
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 716
    Par défaut
    Le serializeur doit etre appelé a deux endroits JobExplorer et JobRepository

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [debutant][serialisation ][jtable]pb de sauvegarde
    Par ould dans le forum Composants
    Réponses: 19
    Dernier message: 20/07/2004, 09h09
  2. [Concept][Sérialisation] XML ou serializable
    Par christopheJ dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 03/06/2004, 13h11
  3. est il possible de serialiser un composant visuel ?
    Par uliss dans le forum C++Builder
    Réponses: 12
    Dernier message: 15/04/2004, 10h22
  4. [VB6]Sérialiser un objet
    Par HPJ dans le forum VB 6 et antérieur
    Réponses: 9
    Dernier message: 11/10/2003, 10h05
  5. Serialiser de gros documents XML
    Par philemon_siclone dans le forum XML/XSL et SOAP
    Réponses: 6
    Dernier message: 17/09/2003, 15h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo