content: /**
   * Copyright (c) 2010-present Abixen Systems. All rights reserved.
   *
   * This library is free software; you can redistribute it and/or modify it under
   * the terms of the GNU Lesser General Public License as published by the Free
   * Software Foundation; either version 2.1 of the License, or (at your option)
   * any later version.
   *
   * This library is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
   * details.
   */
  
  package com.abixen.platform.common.interfaces.web.page;
  
  
  import com.fasterxml.jackson.core.JsonParser;
  import com.fasterxml.jackson.databind.DeserializationContext;
  import com.fasterxml.jackson.databind.JsonDeserializer;
  import com.fasterxml.jackson.databind.JsonNode;
  import com.fasterxml.jackson.databind.node.ArrayNode;
  import org.springframework.data.domain.Sort;
  import org.springframework.data.domain.Sort.Direction;
  import org.springframework.data.domain.Sort.Order;
  
  import java.io.IOException;
  
  public class PlatformSortDeserializer extends JsonDeserializer<Sort> {
  
      @Override
      public Sort deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
          final ArrayNode node = jsonParser.getCodec().readTree(jsonParser);
          final Order[] orders = new Order[node.size()];
  
          int i = 0;
          for (JsonNode jsonNode : node) {
              orders[i] = new Order(Direction.valueOf(jsonNode.get("direction").asText()), jsonNode.get("property").asText());
              i++;
          }
  
          return Sort.by(orders);
      }
  
  }