Skip to content

Instantly share code, notes, and snippets.

View jonikarppinen's full-sized avatar

Joni Karppinen jonikarppinen

View GitHub Profile
@jonikarppinen
jonikarppinen / CustomErrorController.java
Last active June 16, 2021 02:19
Example of replacing Spring Boot "whitelabel" error page with custom error responses (with JSON response body)
package com.company.project.controllers;
import com.company.project.model.api.ErrorJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
@jonikarppinen
jonikarppinen / proguard-project.txt
Last active August 1, 2017 09:56
Example ProGuard config for a project using RxJava, Guava and Gson
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
@jonikarppinen
jonikarppinen / markdown-comments.md
Last active April 10, 2025 20:16
How to comment out stuff in Markdown on GitHub?

Comments in GitHub flavour of Markdown

As answers to this Stack Overflow question reveal, using <!--- and ---> or <!-- and --> works (view source by clicking "Raw"):

@jonikarppinen
jonikarppinen / Question20442265.java
Last active December 30, 2015 17:39
Answer for this question about Gson: http://stackoverflow.com/questions/20442265/how-to-decode-json-with-unknown-field-using-gson. This demonstrates how to use custom deserialiser to parse a big list of properties of the same type but unknown/random/varying names. Besides JDK, depends on Guava library.
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.gson.*;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;