Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BACKLOG-14866] Adding serializers for metrics and data. Extracted co…
…mmon code to base class. Unit tests added
- Loading branch information
1 parent
382be3d
commit ebf26f0
Showing
16 changed files
with
987 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,8 +39,4 @@ public DataEvent( S source, Rows rows ) { | |
super( source, rows ); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
pdi-engine/serializers/src/main/java/org/pentaho/pdi/engine/serializers/BaseSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* ***************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com | ||
* | ||
* ******************************************************************************* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* ***************************************************************************** | ||
* | ||
*/ | ||
|
||
package org.pentaho.pdi.engine.serializers; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.pentaho.di.engine.api.events.PDIEvent; | ||
import org.pentaho.osgi.objecttunnel.TunnelSerializer; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by nbaker on 3/4/17. | ||
*/ | ||
abstract class BaseSerializer<T extends PDIEvent> implements TunnelSerializer<T> { | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
private Class<T> tClass; | ||
|
||
public BaseSerializer( Class<T> tClass ) { | ||
this.tClass = tClass; | ||
} | ||
|
||
@Override public List<Class> getSupportedClasses() { | ||
return Collections.singletonList( tClass ); | ||
} | ||
|
||
@Override public String serialize( Object object ) { | ||
try { | ||
return mapper.writer().writeValueAsString( object ); | ||
} catch ( JsonProcessingException e ) { | ||
throw new RuntimeException( e ); | ||
} | ||
} | ||
|
||
@Override public T deserialize( String serializedString ) { | ||
try { | ||
return mapper.readValue( serializedString, tClass ); | ||
} catch ( IOException e ) { | ||
throw new RuntimeException( e ); | ||
} | ||
} | ||
} |
Oops, something went wrong.