2015-08-07


For a fresh of taste I've installed Mac OS X El Captain(10.11) beta on my Macbook. Everything is fine until I want to upgrade my PHP installation via homebrew.

The result is:

> brew install php56
Warning: You are using OS X 10.11.
We do not provide support for this pre-release version.
You may encounter build failures or other breakage.
==> Installing php56 from homebrew/homebrew-php
==> Downloading https://php.net/get/php-5.6.11.tar.bz2/from/this/mirror
Already downloaded: /Library/Caches/Homebrew/php56-5.6.11
==> ./configure --prefix=/usr/local/Cellar/php56/5.6.11_2 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc
==> make
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sapi/cgi/php-cgi] Error 1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libs/libphp5.bundle] Error 1

READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/homebrew):
  https://github.com/homebrew/homebrew-php/issues

Warning: You are using OS X 10.11.
We do not provide support for this pre-release version.
You may encounter build failures or other breakage.

According to the warning, that is not avoidable with build failure. ;-)

BUT, the problem can be solved with the power of google. :)

---

Open the File /usr/local/Library/Taps/homebrew/homebrew-php/Abstract/abstract-php.rb line 362, replace:
s.change_make_var! "EXTRA_LIBS", "\\1 -lstdc++"
to
s.change_make_var! "EXTRA_LIBS", "\\1 -lstdc++ /usr/local/opt/openssl/lib/libssl.dylib /usr/local/opt/openssl/lib/libcrypto.dylib"

then try to install the php via homebrew again.

via: https://github.com/Homebrew/homebrew-php/issues/1941

GSON makes the conversion JSON to POJO very easily


As a java developer one should know JSONObject very well. On the other hand, if one depends so heavily on JSONObject, the conversion from JSON to POJO becomes sometimes a burden if the structure of JSON string is very complex. One has to write so many codes to call JSONObject.getString("") and so on. Thanks GSON, there is a better way to convert JSON to java object.

 Define a java class to be an exact model of the JSON string like: 
{"book":{"translations":[{"translatedText":"Bonjour tout le monde"}]}} 
The java class:
class BookWrapper {
    public Book book;

    public static BookWrapper fromJson(String s) {
        return new Gson().fromJson(s, DataWrapper.class);
    }
    public String toString() {
        return new Gson().toJson(this);
    }
}
class Book {
    public List<Translation> translations;
}
class Translation { 
    public String translatedText;
}
As you can see, it's very convenient and elegant to use BookWrapper.fromJson(JsonString) to convert a JSON string to the java object.
Furthermore, GSON supports the versioning of a java object. It's helpful when the JSON structure has been changed with some versions.

Usage taken from the GSON user guide:

Versioning Support

Multiple versions of the same object can be maintained by using @Since annotation. This annotation can be used on Classes, Fields and, in a future release, Methods.  In order to leverage this feature, you must configure your Gson instance to ignore any field/object that is greater than some version number.  If no version is set on the Gson instance then it will serialize and deserialize all fields and classes regardless of the version.

public class VersionedClass {
  @Since(1.1) private final String newerField;
  
@Since(1.0) private final String newField;
  private final String field;

  public VersionedClass() {
    this.newerField = "newer";
    this.newField = "new";
    this.field = "old";
  }
}

VersionedClass versionedObject = new VersionedClass();
Gson gson = new GsonBuilder().setVersion(1.0).create();

String jsonOutput = gson.toJson(someObject);
System.out.println(jsonOutput);
System.out.println();gson = new Gson();
jsonOutput = gson.toJson(someObject);
System.out.println(jsonOutput);


======== OUTPUT ========
{"newField":"new","field":"old"}
{"newerField":"newer","newField":"new","field":"old"}