Skip to content

Instantly share code, notes, and snippets.

View jam01's full-sized avatar
🏠
Working from home

Jose Montoya jam01

🏠
Working from home
View GitHub Profile
@jam01
jam01 / jackson-scala-module-mutableMap.scala
Last active November 13, 2019 18:45
ObjectMapper that deserializes JSON to mutable Maps and Seqs while also maintaining order
object ATR extends AbstractTypeResolver {
override def findTypeMapping(config: DeserializationConfig, javaType: JavaType) = {
val result = Some(javaType) collect {
case mapLikeType: MapLikeType =>
if (javaType.getRawClass.equals(classOf[collection.Map[_, _]])) {
TypeFactory.defaultInstance().constructSpecializedType(javaType, classOf[mutable.LinkedHashMap[_, _]])
} else null
case colType: CollectionLikeType =>
if (javaType.getRawClass.equals(classOf[collection.Seq[_]])) {
TypeFactory.defaultInstance().constructSpecializedType(javaType, classOf[mutable.LinearSeq[_]])
@jam01
jam01 / com.example.PasswordCallback.java
Created May 25, 2017 16:25
This bean will allow cxf:proxy-clients to use the same outInterceptor. Useful when multiple clients need to use the same request auth.
public class PasswordCallback implements CallbackHandler {
private Map<String, String> passwords;
public PasswordCallback(String username, String password) {
password.put(username, password);
}
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallBackException {
for (int = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
@jam01
jam01 / dataweave-concatPersonsName.dwl
Created May 25, 2017 15:33
This script will concatenate a regular persons's name into a string while skipping null & empty strings.
%dw 1.0
%output application/json
---
{
result: [
payload.person.firstName,
payload.person.middleName,
payload.person.lastName
]
filter $ != null
@jam01
jam01 / dataweave-skipNullOnExclusiveFields.dwl
Created May 25, 2017 14:43
This script will filter out all null and empty fields except the ones you specify. Useful where for some reason some xml fields have null values but relevant info in the attributes.
%dw 1.0
%output application/xml
---
{
result: payload filter ($ != null and $ != '' or $$ == 'someSpecificField')
}
@jam01
jam01 / dataweave-useFieldAsSelector.dwl
Last active May 25, 2017 16:00
Dataweave script that let's you dynamically use a field selector to select another field. Using squared brackets insteaf of dots allows you to select the field dynamically.
%dw 1.0
%output application/json
---
{
result: payload[payload.someField]
}
@jam01
jam01 / dataweave-mergeArrayOfMaps.dwl
Last active May 25, 2017 16:00
Dataweave script that will take 2 arrays of maps and will output 1 array without duplicates. Used when needing to merge two arrays where one superseeds the other.
%dw 1.0
%output application/xml
---
{
mergedArray: (arrayWithNewValues ++ arrayWithOldValues) distinctBy $.id
}